This example describes the Android font settings and Roboto font usage. Share to everyone for your reference. The specific analysis is as follows:
First, custom fonts
1.android typeface use TTF font file to set fonts
We can put the TTF font file in the program and use typeface to set the font in the program.
The first step is to create a new fonts directory under the assets directory and put TTF font files here.
In the second step, the program calls:
Copy Code code as follows:
Assetmanager mgr=getassets ()/Get Assetmanager
Typeface Tf=typeface.createfromasset (Mgr, "Fonts/ttf.ttf");//According to the path typeface
Tv=findviewbyid (R.id.textview);
Tv.settypeface (TF);//Set Font
2. Use android:textstyle= "bold" in an XML file to set the English bold, but you cannot set the Chinese to bold.
The way to set Chinese in bold is to:
Copy Code code as follows:
TextView TV = (TextView) Findviewbyid (R.ID.TEXTVIEW01);
Tv.getpaint (). Setfakeboldtext (True),//Chinese Imitation "bold"--use Textpaint's faux "bold" setting Setfakeboldtext to True.
Note: Some fonts are not valid in Chinese, although they do not complain, but they are not valid for Chinese.
Ii. Use of Roboto
Since Android4.0 the default font has been used Roboto, here are some ways to use it:
Copy Code code as follows:
android:fontfamily= "Sans-serif"//Roboto Regular
android:fontfamily= "Sans-serif-light"//Roboto Light
android:fontfamily= "sans-serif-condensed"//Roboto Condensed
android:fontfamily= "Sans-serif-thin"//Roboto Thin (Android 4.2)
In combination with
Android:textstyle= "Normal|bold|italic"
The available parameters are as follows:
Regular
Italic
Bold
Bold-italic
Light
Light-italic
Thin
Thin-italic
Condensed Regular
Condensed italic
Condensed Bold
Condensed Bold-italic
I hope this article will help you with your Android program.