TextView setting fonts in Android

Source: Internet
Author: User

Recent projects appear to set the font to the song body, Microsoft Ya Black, bold, italic and other needs;

Mom found Android system supports three fonts by default: "Sans", "serif", "monospace", in addition to other font files (*.TTF)

The code is as follows:

Get TextView Control Object
TextView TextView = (TextView) Findviewbyid (R.id.custom);
Save the font file in the assets/fonts/directory and create the typeface object
Typeface Typeface = Typeface.createfromasset (Getassets (), "Fonnts/fangsongti.ttf");

Use fonts as Fangsong
Textview.settypeface (TypeFace);

Description: Currently Android mainly for Latin language can use font settings, Chinese temporarily do not support; You must create a fonnts folder under assets, and put the font file (. ttf) you want to use, and provide a relative path to Createfronasset () To create a typeface object. However, Android support for fonts is not very good, some font files may not be supported, but also do not error, just use the default font style during the run. In addition, if not the needs of the project, try not to use, the resources are too large, will greatly increase the size of the app.

Font Library Reference Link: Http://pan.baidu.com/s/1bocW0TT

TextView setting fonts in Android

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.