Custom font settings in Android are generally set through the Facetype property, first look at the methods provided by the official website
As the name implies, we can use the asset files under the assets file in the project or the system files of Android itself to make font settings.
If you use the assets method, first we need to create the assets folder under the project path.
, after you have set up the file, you can use
Typeface typeface1 = Typeface.createFromAsset(this.getAssets(),"fonts/1.TTF"); tvText1.setTypeface(typeface1);
method or customize a TextView subclass
public class MyTextView extends TextView {public MyTextView(Context context) { super(context);}public MyTextView(Context context, AttributeSet attrs) { super(context, attrs);}public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr);}@Overridepublic void setTypeface(Typeface tf, int style) { super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "2.tff"));}
}
If you use system files, the path settings need to be aware that the path setting needs to start at the time of the reference.
Typeface tf = Typeface.createFromFile("/system/fonts/AndroidClock.ttf")
With these methods, you can implement a custom TextView text style
#Android Custom Font Styles