Android font setting and Roboto font usage

Source: Internet
Author: User

Android font setting and Roboto font usage
I. Custom Fonts

1. android Typeface uses TTF font files to set fonts

We can put the ttf font file in the program and set the font using Typeface in the program.
Step 1: Create the fonts directory under the assets Directory and put the ttf font file here.
Step 2: Call in the program:

AssetManager mgr = getAssets (); // obtain AssetManagerTypeface tf = Typeface. createFromAsset (mgr, "fonts/ttf. ttf "); // obtain Typefacetv = findViewById (R. id. textview); TV. setTypeface (tf); // set the font

 

2. Use android: textStyle = "bold" in the xml file to set English to bold, but not Chinese to bold,
The method to set Chinese to bold is:

 

TextView TV = (TextView) findViewById (R. id. textView01); TV. getPaint (). setFakeBoldText (true); // Chinese imitation "bold" -- use TextPaint imitation "bold" to set setFakeBoldText to true.

 

Note: Some fonts in Chinese are invalid. Although no error is reported, they are invalid for Chinese. 2. RoBoto is used by default since Android4.0. The following describes how to use it:

 

 

android:fontFamily="sans-serif" // roboto regularandroid:fontFamily="sans-serif-light" // roboto lightandroid:fontFamily="sans-serif-condensed" // roboto condensedandroid:fontFamily="sans-serif-thin" // roboto thin (android 4.2)//in combination withandroid:textStyle="normal|bold|italic"

 

Available parameters:

Regular
Italic
Bold
Bold-italic
Light
Light-italic
Thin
Thin-italic
Condensed regular
Condensed italic
Condensed bold
Condensed bold-italic



 

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.