First of all, if the Android internal fonts are not the fonts we need, then we need to import the font files into the Android development project, we will explain in detail in the afternoon:
1. We first analyze that I want the font of the text in the TextView control is: Chinese in italics , we found that this is not available within the Android system, so we have to import the italic file ourselves. TTF
We put the font file of Chinese italics into the assets folder, create a new Fonts folder to store Droidsansfallback.ttf files, such as:
And then how to call this font in the program:
1 protected voidonCreate (Bundle savedinstancestate) {2 Super. OnCreate (savedinstancestate);3 Setcontentview (r.layout.activity_main);4 Assetmanager mgr = Getassets (); 5 Typeface tf = Typeface.createfromasset (Mgr, "Fonts/droidsansfallback.ttf"); 6 7TextView Sentence1 =(TextView) Findviewbyid (r.id.textview1);8TextView Sentence2 =(TextView) Findviewbyid (R.ID.TEXTVIEW2);9 Ten Sentence1.settypeface (TF); One Sentence2.settypeface (TF); A}
2. The specific steps can be summarized as follows:
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:
Assetmanager mgr=getassets ();//Get Assetmanager
Typeface Tf=typeface.createfromasset (Mgr, "Fonts/ttf.ttf");//Typeface by Path
Tv.settypeface (TF);//Set Font
Android (Java) Learning note 100:android developing font changes