Android uses the specified font

Source: Internet
Author: User

1, Android provides three kinds of fonts: "Sans", "serif" and "monospace". Use Android:typeface, such as android:typeface= "monospace".

2. If you want to use a different font,

1) Copy the TTF file of the new font to the assets/fonts/directory, for example, we copy the "*.ttf" to the past.

2) We need to set the widget to that font, which, unfortunately, cannot be done directly in the XML file and requires writing the source code.

TextView TV = (TextView) Findviewbyid (R.id.c12_custom); Typeface face = Typeface.createfromasset (Getassets (), "Fonts/timesi.ttf"); Tv.settypeface (face);

Get the resources from the Assert, get the app's assert, use Getaserts (), by giving the relative path below the assert/. In actual use, the font library may exist on the SD card, you can use CreateFromFile () to replace the Createfromasset.

I have imported Chinese Xingkai fonts in the simulator, about 4M, but the system does not recognize the font, no display, and then try to use the English font Timesi.ttf, normal. Therefore, Android is not compatible with all TTF fonts, especially in the Chinese special font support will be problematic, for incompatible fonts, Android can not error, but not normal display. In general, we will use the default fonts provided by the system


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.