Different font for Some activities using Calligraphy Library

后端 未结 2 1925
太阳男子
太阳男子 2021-02-19 08:02

I am using Calligraphy Library for using custom font in my application. I set a custom font to my whole application by default font using CalligraphyConfig, in my <

相关标签:
2条回答
  • 2021-02-19 08:31

    Looks like it's because of AppCompat creating a different version of buttons/textviews at runtime.

    In your Calligraphy startup in your Application, add the line:

    .addCustomStyle(AppCompatTextView.class, android.R.attr.textViewStyle)
    

    to end up with something like:

    @Override
    public void onCreate() {
        super.onCreate();
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                                .setDefaultFontPath("fonts/some-other-custom-font.ttf")
                                .addCustomStyle(AppCompatTextView.class, android.R.attr.textViewStyle)
                                .setFontAttrId(R.attr.fontPath)
                                .build()
                );
        //....
    }
    

    And that should take care of your textviews.

    Edit:

    This should now be fixed with https://github.com/chrisjenx/Calligraphy/pull/191, currently as a snapshot.

    0 讨论(0)
  • 2021-02-19 08:38

    Not Best Solution however better than custom font in that activity.

    I just removed

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

    from activity where I was trying to change font. In That activity using default android font which is better than that custom font for my other activities.

    0 讨论(0)
提交回复
热议问题