Issue
My android app has its own language, which can be not equal with device system language. For ex - MyApp has 'ru' language, but phone has 'en' lang. Can i do smth with app to take my app language locale resources, not by system language?
PS - my app language I changing by this code:
public static void setLocale(String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
SvoApplication.getContext().getResources().updateConfiguration(config,
SvoApplication.getContext()
.getResources()
.getDisplayMetrics());
SharedPreferencesManager.setCurrentLanguage(language);
}
And all data that have taken from db is localized by sharedPref value of app language
PPS - i understand that i must use strings-en.xml/strings-ru.xml or etc. And it worked when i change my app lang. But when i rotate screen for example - all resources are changing to what system default language is
Solution
you can just override the onConfigurationChanged method in your class which extends Application.class. And set the config.locale same as above
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
/*here code to set locale*/
}
and now it will work fine, when you rotate your screen.
Answered By - Moses
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.