语言更改后刷新android应用程序
我正在开发一个支持两种语言的应用程序。有一个切换按钮可以改变语言。我用下面的代码来改变语言环境,一切正常语言更改后刷新android应用程序,android,locale,multilingual,Android,Locale,Multilingual,我正在开发一个支持两种语言的应用程序。有一个切换按钮可以改变语言。我用下面的代码来改变语言环境,一切正常 Resources res = viewDashBoardScreen.getResources( // Change locale settings in the app. DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration();
Resources res = viewDashBoardScreen.getResources(
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale("es".toLowerCase());
res.updateConfiguration(conf, dm);
问题:语言更改后如何刷新整个应用程序
目前我正在重新启动更改语言的活动。它工作得很好,但它是良好的实践吗?或者是否有其他方法可以在应用程序中应用语言更改
如果您有任何帮助,我们将不胜感激。谢谢。我想您可以在togal按钮更改时调用此功能,它对我有效
private void setLocale(String localeCode){
AppLog.logString(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);
}
在toggel按钮上,通过以下方式更改调用函数:
setLocale("en-us");// pass languen in whicy u want to translate
setLocale("ar",savedInstanceStat);
你有没有解决办法?