【问题标题】:Refresh android application after language change语言更改后刷新android应用程序
【发布时间】:2013-09-19 03:37:00
【问题描述】:

我正在开发一个支持两种语言的应用程序。有一个切换按钮可以更改语言。我正在使用以下代码更改语言环境,一切正常。

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);

问题:更改语言后如何刷新整个应用?

目前我正在重新启动更改语言的活动。它工作正常,但这是一个好习惯吗?或者有没有其他方法可以在应用程序中应用语言更改。

任何帮助将不胜感激..谢谢。

【问题讨论】:

  • 你有没有解决方案?

标签: android locale multilingual


【解决方案1】:

你可以调用这个函数当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 buttong 以这种方式更改呼叫功能:

setLocale("en-us");// pass languen in whicy u want to translate 
setLocale("ar",savedInstanceStat);  

【讨论】:

    猜你喜欢
    • 2016-10-27
    • 2018-04-15
    • 2021-03-27
    • 2015-06-19
    • 2011-12-24
    • 2015-05-09
    • 2018-05-27
    • 2013-02-18
    • 2013-03-04
    相关资源
    最近更新 更多