编辑:
在 SharedPref 中保存选择的语言:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Lang",ChoosenLang);
editor.commit();
在 onCreate 中获取价值
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String Language = preferences.getString("Lang","de");
if (Language != null && !Language.isEmpty()) {
// Your Language code here
locale = new Locale(Language); // Language=de
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}