First step: Create a new Android project, create a new folder in the assets directory, the name can be arbitrary,
I'm named fonts here.
Step two: Copy the font file to this new directory (there are many font files in the C:\Windows\Fonts directory in the Windows system)
Step three, create a static method under Mainactivity
//Because reading a font file into memory is a time-consuming operation, if the font file is larger, there will beIt is obvious that the typeface can be defined as a global variable, then you can add a judgment, if the typeface exists, it is called directly, if it does not exist, then create, so that the words can only be read into one time, do not have to read in every time Public StaticTypeface Typeface; Public Static void setfonts(Context Context,textview TV) {if(typeface==NULL){//The font file is read into memory and becomes a font file objectAssetmanager mgr = Context.getassets ();//Strictly case-sensitive, extension.String Path ="Fonts/impact. TTF "; typeface = Typeface.createfromasset (mgr, path); }//Use typeface font file ObjectTv.settypeface (typeface); }//Apply FontSetfonts (CONTEXT,TV);
Android App text font settings