1, the Android system defaults to support three kinds of fonts, respectively: "Sans", "serif", "monospace
2, in Android can introduce other fonts.
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
android:layout_marginright= "4PX"
android:text= "Sans:"
Android:textsize= "20SP" >
Android:id= "@+id/sans"
android:text= "Hello,world"
Android:textsize= "20SP"
Android:typeface= "Sans" >
android:layout_marginright= "4PX"
android:text= "serif:"
Android:textsize= "20SP" >
Android:id= "@+id/serif"
android:text= "Hello,world"
Android:textsize= "20SP"
android:typeface= "Serif" >
android:layout_marginright= "4PX"
android:text= "Monospace:"
Android:textsize= "20SP" >
Android:id= "@+id/monospace"
android:text= "Hello,world"
Android:textsize= "20SP"
Android:typeface= "Monospace" >
android:layout_marginright= "4PX"
android:text= "Custom:"
Android:textsize= "20SP" >
Android:id= "@+id/custom"
android:text= "Hello,world"
Android:textsize= "20SP" >
Get TextView Control Object
TextView TextView = (TextView) Findviewbyid (R.id.custom);
Save the font file in the assets/fonts/directory, www.linuxidc.com create the typeface object
Typeface typeface = Typeface.createfromasset (Getassets (), "Fonts/droidsansthai.ttf");
Apply Font
Textview.settypeface (typeface);
If you want to apply a custom font to all controls on the entire interface, you can:
Package arui.blog.csdn.net;
Import android.app.Activity;
Import Android.graphics.Typeface;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.Button;
Import Android.widget.EditText;
Import Android.widget.TextView;
public class Fontmanager {
public static void Changefonts (ViewGroup root, Activity Act) {
typeface tf = Typeface.createfromasset (Act.getassets (),
"Fonts/xxx.ttf");
for (int i = 0; i < Root.getchildcount (); i++) {
View v = root.getchildat (i);
if (v instanceof TextView) {
((TextView) v). Settypeface (TF);
else if (v instanceof Button) {
((Button) v). Settypeface (TF);
else if (v instanceof edittext) {
((EditText) v). Settypeface (TF);
else if (v instanceof viewgroup) {
Changefonts ((viewgroup) v, ACT);
}
}
}
}
Note : For more wonderful tutorials, please pay attention to the Triple graphics tutorial channel,