1, the Android system supports three fonts by default, namely: "Sans", "serif", "monospace" system default mode (tested by default using Sans);
2. Other fonts can be introduced in Android
3. Examples are as follows:
4. layout file
Main.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<tablelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<TableRow>
<textview android:text= "sans:"
android:layout_marginright= "4PX"
Android:textsize= "20SP" ></TextView>
<!--Use the default sans font--
<textview android:id= "@+id/sans"
android:text= "Hello,world"
android:typeface= "sans"
android:textsize= "20SP"></TextView>
</TableRow>
<TableRow>
<textview android:text= "serif:"
android:layout_marginright= "4PX"
Android:textsize= "20SP" ></TextView>
<!--Use the default serifs font--
<textview android:id= "@+id/serif"
android:text= "Hello,world"
android:typeface= "Serif"
android:textsize= "20SP"></TextView>
</TableRow>
<TableRow>
<textview android:text= "monospace:"
android:layout_marginright= "4PX"
Android:textsize= "20SP" ></TextView>
<!--Use the default monospace font--
<textview android:id= "@+id/monospace"
android:text= "Hello,world"
android:typeface= "Monospace"
android:textsize= "20SP"></TextView>
</TableRow>
<!--There is no font set, we'll set it in Java code--
<TableRow>
<textview android:text= "Custom:"
android:layout_marginright= "4PX"
android:textsize= "20SP" ></TextView>
<textview android:id= "@+id/custom"
android:text= "Hello,world"
android:textsize= "20SP"></TextView>
</TableRow>
</TableLayout>
5. Java code
Package yyl.fonts;
Import android.app.Activity;
Import Android.graphics.Typeface;
Import Android.os.Bundle;
Import Android.widget.TextView;
public class Fontsactivity extends activity {
/** called when the activity is first created. */
@Override
public void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
//Get TextView Control object
TextView TextView = (TextView) Findviewbyid (r.id.custom);
Save the font file in the assets/fonts/directory and create the typeface object
Typeface Typeface = Typeface.createfromasset (Getassets (), "Fonts/handmadetypewriter.ttf");
Apply Font
Textview.settypeface (TypeFace);
}
}
Android TextView set Chinese font bold implementation method
English setting bold can be set in XML:
The code is as follows:
<span style= "font-size:18px" >android:textstyle= "bold" </SPAN>
English can also be directly in the string file directly fill in this way:
The code is as follows:
<string name= "Styled_text" >plain, <b>bold</b>, <i>italic</i>, <b><i> Bold-italic</i></b></string>
B code Bold, I stands for tilt
The Chinese setting is bold and you need to get the current TextView in your code to set it up:
The code is as follows:
TextView TV = (TextView) Findviewbyid (r.id.tv);
Textpaint TP = Tv.getpaint ();
Tp.setfakeboldtext (TRUE);
Android Font Related summary