I want to change the language in all activity. Is there any simple way to change the language without using string resource.I have tried something like below code,but not works.Any one help me to change the language in all activity by simple way?
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView arg0, View arg1,
int arg2, long arg3) {
Configuration config = new Configuration();
switch (arg2) {
case 0:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LocalizationUpdaterActivity.this);
preferences.edit().putString("lang", "ar").commit();
break;
case 1:
break;
default:
config.locale = Locale.TAIWAN;
break;
}
}
public void onNothingSelected(AdapterView arg0) {
// TODO Auto-generated method stub
}
});
Application code:
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String lang = preferences.getString("lang", "en");
Locale locale = new Locale(lang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
}
}