1

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

1

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

yes this working but after restart app I have changed UI language. But thx.
1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.