Android font settings-Typeface

Source: Internet
Author: User

Android font settings-Typeface
Control font settings

Common Font types include:

Typeface. DEFAULT // Regular font type

Typeface. DEFAULT_BOLD // font type

Typeface. MONOSPACE // same width font type

Typeface. SANS_SERIF // sans serif font type

Common font style names include:

Typeface. BOLD // BOLD

Typeface. BOLD_ITALIC // bold italic

Typeface. ITALIC // ITALIC

Typeface. NORMAL // regular
1. Set in xml.
Use android: typeFace to set:
Android: typeface = "sans"
2. In the Java program:
Eg1:
Typeface font = Typeface. create (Typeface. SANS_SERIF, Typeface. BOLD );
P. setTypeface (font );
Eg2:
String familyName = "";
Typeface font = Typeface. create (familyName, Typeface. BOLD );
P. setTypeface (font );

Use external font

1. First copy the fonts file to the fonts directory under assets.
2. The Code is as follows:

Private void mySetTypeFace () {// TODO Auto-generated method stub // obtain resources from assert to obtain the assert of the app. getAserts () is used to obtain the assert of the app (), by providing the relative path under assert. In actual use, the library may exist on the SD card. You can use createFromFile () to replace createFromAsset. Typeface face = Typeface. createFromAsset (getAssets (), "fonts/HanYi. ttf"); // title is the control defined between. setTypeface (face );}

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.