I'm using this application class to set my locale all over my application
public class MyApplication extends Application {
public static void updateLanguage(Context ctx) {
SharedPreferences prefs = getDefaultSharedPreferences(ctx);
String lang = prefs.getString("locale_override", "");
updateLanguage(ctx, lang);
}
public static void updatefont(Context ctx) {
SharedPreferences prefs = getDefaultSharedPreferences(ctx);
String lang = prefs.getString("locale_override", "");
if (lang.equals("ar")) {
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/Cairo-Regular.ttf")
.setFontAttrId(R.attr.fontPath)
.build()
);
} else {
}
}
public static void updateLanguage(Context ctx, String lang) {
Configuration cfg = new Configuration();
if (!TextUtils.isEmpty(lang))
cfg.locale = new Locale(lang);
else
cfg.locale = Locale.getDefault();
ctx.getResources().updateConfiguration(cfg, null);
}
@Override
public void onCreate() {
updateLanguage(this);
updatefont(this);
super.onCreate();
}
}
it work's fine but when I test it on Nexus 5X API 27 emulator device it doesn't work at all . all solutions not working