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 );}