Issue
I have a Spinner
with three language choice on login page. I want when user choose one language suppose "Persian" language the language of whole application should change. I am able to change language of current Activity
only. How can I change the language of whole application.
Solution
Change Language Programmatically in Android
Here is the appropriate way of changing the locale of the application:
There are some difficulties which you have to overcome to change the language programmatically.
1.)Your application will not remember your language change after it is closed or recreated during the configuration change.
2.)You should update currently visible UI properly according to the selected language.
Solution
“LocaleHelper
” is the solution all you need. You just have to initialize locale on your application’s main class. After that all your language changes will persist.
After the recent changes in Android API Version 24(Nougat) we need to override attachBaseContext to reflect changes.
Below method used to change language for application :
private static boolean updateResources(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
configuration.locale = locale;
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
return true;
}
find more details in below link :
Changing Android’s Locale Programmatically
Answered By - Chetan Joshi
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)