更改Android应用程序的语言
问题描述:
在我的应用程序我有一个特别的菜单,我可以改变应用程序language.I得到项目API标签(通过解析JSON)和项目价值xml.Can更改Android应用程序的语言,而不应用和сhangibg系统语言重新启动。
In my app I have a special menu where I can change application language.I get labels from project API(by parsing JSON) and project values xml.Can I change android application language without restart of application and сhangibg system language.
答
插入此方法,并调用它的改变语言。
Insert this method and call it for changing the language.
private void setLocale (String localeCode , Bundle b ){
Log.d(TAG+"set location function: "+localeCode);
locale = new Locale(localeCode);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
getApplicationContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
UserDetail.this.getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
onCreate(null);
}
在切换改变或任何这样的选择调用值:
On toggle change or any selection call value like this:
setLocale("en-us",savedInstanceStat); // for english
setLocale("ar",savedInstanceStat); // for arabic