One, custom fonts
1.android typeface setting fonts using TTF font files
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 place the TTF font file here.
In the second step, the program calls:
?
1234567 |
AssetManager mgr=getAssets(); //得到AssetManager Typeface tf=Typeface.createFromAsset(mgr, "fonts/ttf.ttf" ); //根据路径得到Typeface tv=findViewById(R.id.textview); tv.setTypeface(tf); //设置字体 |
2. Use the android:textstyle= "bold" in the XML file to set the English to bold, but you cannot set the Chinese to bold,
The way to set Chinese to bold is:
?
12 |
TextView tv = (TextView)findViewById(R.id.TextView01); tv.getPaint().setFakeBoldText( true ); //中文仿“粗体”--使用TextPaint的仿“粗体”设置setFakeBoldText为true。 |
Note: Some fonts in Chinese are not valid, although they will not be error, but not Chinese. Second, the use of Roboto
The default font has been used Roboto since Android4.0, and here's how to use it:
?
123456 |
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" |
Available parameters:
Regular
Italic
Bold
Bold-italic
Light
Light-italic
Thin
Thin-italic
Condensed Regular
Condensed italic
Condensed Bold
Condensed Bold-italic
A companion tour, a free dating site: www.jieberu.com
Push family, free tickets, scenic spots: www.tuituizu.com
Android font settings, Roboto font use