How to change android app locale/language runtime/programmatically, best practice way?
I've looked other solutions on so but they got depreciated accepted solutions. Hope to this will be future reference.
How to change android app locale/language runtime/programmatically, best practice way?
I've looked other solutions on so but they got depreciated accepted solutions. Hope to this will be future reference.
For Android < N
Locale locale = new Locale(mLanguageCode);
Locale.setDefault(locale);
Configuration config = mContext.getResources().getConfiguration();
config.locale = locale;
mContext.getResources().updateConfiguration(
config,
mContext.getResources().getDisplayMetrics()
);
activity.recreate();
For >= N
Locale locale = new Locale(mLanguageCode);
Locale.setDefault(locale);
Configuration config = mContext.getResources().getConfiguration();
config.setLocale(locale);
mContext.getResources().updateConfiguration(
config,
mContext.getResources().getDisplayMetrics()
);
activity.recreate();