Tuesday, October 26, 2010

How to change language/locale within Android application

If you want to change language/locale from your Android application (not in system settings), following code works for me:


public void changeLocale(Locale locale) {
Locale.setDefault(locale);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = locale;
res.updateConfiguration(conf, dm);

finish();
Intent intent = new Intent(getApplicationContext(),
this.getClass());
intent.setAction(Intent.ACTION_CONFIGURATION_CHANGED);
startActivity(intent);
}

No comments:

Post a Comment