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