How to Set a Custom Font in the ActionBar Title?

后端 未结 17 1781
面向向阳花
面向向阳花 2020-11-22 09:46

How (if possible) could I set a custom font in a ActionBar title text(only - not the tab text) with a font in my assets folder? I don\'t want to use the android:logo option.

17条回答
  •  情书的邮戳
    2020-11-22 10:13

    The Calligraphy library let's you set a custom font through the app theme, which would also apply to the action bar.

    
    
    
    

    All it takes to activate Calligraphy is attaching it to your Activity context:

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(new CalligraphyContextWrapper(newBase));
    }
    

    The default custom attribute is fontPath, but you may provide your own custom attribute for the path by initializing it in your Application class with CalligraphyConfig.Builder. Usage of android:fontFamily has been discouraged.

提交回复
热议问题