Reputation: 1416
Is it possible in Android dynamic set language string source?
Example: I have in app 2 language resources, now I need force one layout file and here I want use for example English resources but system and UI etc must stay in default language. I want only set language resources for one xml file not for whole system. Is this possible? Or any idea. Thx
Upvotes: 1
Views: 1039
Reputation: 12368
Use this
Resources res = context.getResources(); // Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(language_code.toLowerCase());
res.updateConfiguration(conf, dm);
Upvotes: 1
Reputation: 2737
Use this to change the language Dynamically:
Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);
You can get the list of country code from here.
Upvotes: 2