3

Possible Duplicate:
Set Locale programatically

I would like to create an english/spanish option choice on the initial screen of my app and was wondering if I can utilize Android's excellent language forking without sending the user through the settings to alter the entire device's language settings.

I understand how to kludge it together myself if that's not possible and just set all my values manually, but was hoping that I'm overlooking some way to just have Android use its language system for my app, even as the rest of the system remains in whatever it was preset to.

TIA

Community
  • 1
  • 1
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236

2 Answers2

3

Yes, it is possible to set the language via your Android app so that the change is only visible from your app:

Locale locale = new Locale("us");
Locale.setDefault(locale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, this.getResources().getDisplayMetrics()); 

I think this will help you.

Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109
Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37
2
Resources res = getApplicationContext().getResources();

Locale locale = new Locale("us");
Locale.setDefault(locale);

Configuration config = new Configuration();
config.locale = locale;

res.updateConfiguration(config, res.getDisplayMetrics());
Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250