如何在Android中选择选项language
后刷新应用。
选择后退活动后,布局不刷新。
这是我的代码。
Locale localeIdn = new Locale("in");
Locale.setDefault(localeIdn);
Configuration config1 = new Configuration();
config1.locale = localeIdn;
getBaseContext().getResources().updateConfiguration(config1, getBaseContext().getResources().getDisplayMetrics());
finish();
Intent intent = new Intent(SettingPageActivity.this, MainActivity.class);
startActivity(intent);
break;
答案 0 :(得分:0)
试试这个:
Intent intent = getIntent();
finish();
startActivity(intent);
或者这个:
this.recreate();
答案 1 :(得分:0)
希望它对你有用。
Locale locale = new Locale("yourlanguageid");
LanguageHelper.changeLocale(mActivity.getResources(), locale);
Intent intent = new Intent(mActivity, mActivity.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(intent);
public class LanguageHelper {
/**
* Change locale.
*
* @param res the res
* @param locale the locale
*/
public static void changeLocale(Resources res, String locale) {
Configuration config;
config = new Configuration(res.getConfiguration());
switch (locale) {
case "yourlanguageid":
config.locale = new Locale("yourlanguageid");
break;
case "en":
config.locale = Locale.ENGLISH;
break;
}
res.updateConfiguration(config, res.getDisplayMetrics());
}
public static Locale getLocale(Resources res) {
Configuration config;
config = new Configuration(res.getConfiguration());
return config.locale;
}
}