Is it possible to set a custom font for entire of application?

后端 未结 25 2690
日久生厌
日久生厌 2020-11-22 02:44

I need to use certain font for my entire application. I have .ttf file for the same. Is it possible to set this as default font, at application start up and then use it else

相关标签:
25条回答
  • 2020-11-22 03:22

    its very simple... 1.Download and put ur custom font in assets..then write one separate class for text view as follows: here i used futura font

    public class CusFntTextView extends TextView {
    
    public CusFntTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
    
    public CusFntTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    
    public CusFntTextView(Context context) {
        super(context);
        init();
    }
    
    private void init() {
        if (!isInEditMode()) {
            Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "Futura.ttf");
            setTypeface(tf);
        }
    }
    

    }

    and do the following in xml :

     <com.packagename.CusFntTextView
            android:id="@+id/tvtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"         
            android:text="Hi Android"           
            android:textAppearance="?android:attr/textAppearanceLarge"
          />
    
    0 讨论(0)
提交回复
热议问题