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

后端 未结 25 2672
日久生厌
日久生厌 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:15

    I would suggest extending TextView, and always using your custom TextView within your XML layouts or wherever you need a TextView. In your custom TextView, override setTypeface

    @Override
    public void setTypeface(Typeface tf, int style) {
        //to handle bold, you could also handle italic or other styles here as well
        if (style == 1){
            tf = Typeface.createFromAsset(getContext().getApplicationContext().getAssets(), "MuseoSans700.otf");
        }else{
            tf = Typeface.createFromAsset(getContext().getApplicationContext().getAssets(), "MuseoSans500.otf");
        }
        super.setTypeface(tf, 0);
    }
    

提交回复
热议问题