Entire project to use a third-party font first place the font file under the Assets folder
Because the whole project is going to use a third-party font here I rewrote the TextView Button EditText three controls
Take TextView as an example code to replace inheritance as other controls
Public classCustomtextviewextendsTextView { PublicCustomtextview (Context context) {Super(context); Init (context); } PublicCustomtextview (Context context, AttributeSet attrs) {Super(context, attrs); Init (context); } PublicCustomtextview (context context, AttributeSet attrs,intDefsyle) { Super(context, attrs, Defsyle); Init (context); } /*** * Set Font * *@return */ Public voidinit (Context context) {Settypeface (Fontcustom.setfont (context)); }}View Code
Public classFontcustom {StaticString Fongurl = "Fonts/fzltxh_gbk.ttf"; StaticTypeface TF; /*** * Set Font * *@return */ Public StaticTypeface SetFont (context context) {if(tf==NULL) {tf=Typeface.createfromasset (Context.getassets (), fongurl); } returnTF; }}View Code
How to use
< Customtextview Android:layout_width = "Match_parent" android:layout_height= "Wrap_content" android:text= "I am a custom font" android:textcolor= "@color/login_font_hit" android:textsize= " 14.0sp "/>
View Code
This enables the unified style of the project font
Android uses a custom font