chrisjenx / Calligraphy

Custom fonts in Android the easy way...
Apache License 2.0
8.59k stars 1.1k forks source link

How to apply BaseActivity's CalligraphyContextWrapper in Android 26 ? #397

Closed dor506 closed 5 years ago

dor506 commented 7 years ago

Hi

In android 25 and above, updateConfiguration is deprecated https://developer.android.com/reference/android/content/res/Resources.html#updateConfiguration(android.content.res.Configuration,%20android.util.DisplayMetrics)

Until now I used this function to apply language for the application ("iw" language). But it is no longer working in android 26

There's a nice fix for that: https://stackoverflow.com/questions/39705739/android-n-change-language-programatically/40849142#40849142

The problems is that it does the same thing as you do in BaseActivity's attachBaseContext method.

How to combine both of them then?

Thanks In Advance!

ahmedalaa92 commented 7 years ago

have you found a solution yet ?

rahulabrol commented 7 years ago

any update on it?

SudaNix commented 6 years ago

You have to wrap both ContextWrapper

@Override
    protected void attachBaseContext(Context newBase) {
        ContextWrapper localeContextWrapper  = LocaleContextWrapper.wrap(newBase, new Locale("en", "US"));
        ContextWrapper calligraphyContextWrapper = CalligraphyContextWrapper.wrap(localeContextWrapper);
        super.attachBaseContext(calligraphyContextWrapper);
    }
chrisjenx commented 5 years ago

Thanks @SudaNix