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

steve Lee
  • 11
  • 3

3 Answers3

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

Lobo Mau
  • 9
  • 2
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());
Vickyexpert
  • 3,147
  • 5
  • 21
  • 34