1

When user changes the system locale from US to China. I don't want to change the language from English to Chinese in my app, I expect that my app's language still in English.

May I do this by setting a android attribute in AndroidManifest.xml?

Thanks

4
  • 1
    If you don't provide alternate strings.xml for other Locales you application language won't change. Commented Jun 18, 2016 at 6:58
  • yes it is, but my app provides both strings.xml. I don't want to remove them. I think this is a weird requirement. Commented Jun 18, 2016 at 7:06
  • Is this what you need? stackoverflow.com/questions/4985805/set-locale-programatically Commented Jun 18, 2016 at 7:11
  • thank Emran, Can I do this in AndroidManifest.xml? Commented Jun 18, 2016 at 7:23

3 Answers 3

1

I think it would be better to do this once and put your code in your application class

 public class MyApplication extends Application { @Override protected void attachBaseContext(Context base) { Resources res = base.getResources(); Locale locale = new Locale("en"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; res.updateConfiguration(config, res.getDisplayMetrics()); super.attachBaseContext(base); } } 
Sign up to request clarification or add additional context in comments.

Comments

1

If you just want the Chinese xml to stay in the app but not plan in using it, you can simply comment all its content, and the App will consider only the English strings

Comments

0

You can use below code to maintain locale as per your requirement,

 Locale locale = new Locale("en"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); 

1 Comment

Thank Vickyexpert. If I can do this in the androidManifest.xml, I think it will be perfect.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.