Androidstudio to implement the method of loading font resources
The font format in Android doesn't always look perfect, so it requires us to use some aesthetically pleasing fonts, loaded in the same way as HTML fonts, and we need to load fonts to use fonts that are not available in Android.
First find the Assets folder in Androidstudio (under Serc/main/java, in the same file as res), locate the font file (*.ttf) and put it in the folder (for the sake of specification, of course, We can asseets to create a font folder to represent the fonts file. As shown in the figure:
After the resource is stored successfully, the font is loaded and used by 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, and attentive students can see that my assert has two identical font files,
One of them is under the font folder, and 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 shows the Settypeface.