The format of the fonts in Android is always not the perfect display, and asked us to use some beautiful fonts, loading the way (like HTML font), we need to load the font to use the font is not available in Android;
First find the Assets folder in the Androidstudio, (located under Serc/main/java, and res in the same file), find the font file (*.ttf) into this folder (of course, for the sake of specification, We can set up a font folder to represent the fonts file asseets. :
After the resource has been successfully stored, the font is loaded and used through the code:
where the Context.getassets () method is used to load the assets folder, "Opensans-regular.ttf" is the relative path of the font file, the attentive classmate can see that my assert has two identical font files,
One of the following is under the Font folder, if you want to load this folder you need to use:
Typeface tf = Typeface.createfromasset (Getassets (), "Font/opensans-regular.ttf");
The use of this font in view is Settypeface.
How do I load font resources in Androidstudio?