如何在android APP中设置系统语言

2024-11-15 11:31:24
推荐回答(1个)
回答(1):

private void setLanguage(int language) {
try {
Configuration config = getResources().getConfiguration();
DisplayMetrics dm = getResources().getDisplayMetrics();
if (language == Common.LANGUAGE_EN) {
config.locale = Locale.ENGLISH;
} else {
config.locale = Locale.SIMPLIFIED_CHINESE;
}
getResources().updateConfiguration(config, dm);

SharedPreferences sp = getSharedPreferences("userinfo", 0);
SharedPreferences.Editor editor=sp.edit();
editor.putInt("locale", language);
editor.commit();
} catch (Exception e) {
e.printStackTrace();
}
}