android:在没有重新加载/重新启动应用程序的情况下即时反映UI语言更改

Sai*_*ira 5 layout user-interface android localization

我的应用程序中有一个设置,允许用户选择不同的本地化(语言),即Chinese, German, etc.

我想做的是,一旦用户做出选择,立即用当前所选语言的字符串更新布局.当然,我希望将lang更改传播到所有当前活动,而无需重新加载应用程序.

我发现了这个(还没有尝试过),但是想知道是否有更清洁的方法.

http://www.tutorialforandroid.com/2009/01/force-localize-application-on-android.html

格拉西亚斯

Mil*_*kla 2

我也遇到了这个问题。我使用了下面的代码,然后它更改了语言而不刷新活动

public void setLocale(String lang) {

    myLocale = new Locale(lang);
    Resources res = getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.locale = myLocale;
    res.updateConfiguration(conf, dm);
    onConfigurationChanged(conf);
    /*Intent refresh = new Intent(this, AndroidLocalize.class);
    startActivity(refresh);*/
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
  // refresh your views here
    lblLang.setText(R.string.langselection);
  super.onConfigurationChanged(newConfig);
}
Run Code Online (Sandbox Code Playgroud)

我希望它能帮助你......