android:即时反射(reflect) UI 语言更改,无需重新加载/重新启动应用程序

标签 android user-interface layout localization

我的应用程序中有一个设置允许用户选择不同的本地化(语言),即中文、德语等

我想做的是,一旦用户做出选择,立即使用当前所选语言的字符串更新布局。当然,我希望在不重新加载应用程序的情况下将语言更改传播到所有当前 Activity 。

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

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

谢谢

最佳答案

我也有这个问题。我使用了下面的代码,然后它在没有刷新 Activity 的情况下更改了语言

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

希望对你有所帮助..........

关于android:即时反射(reflect) UI 语言更改,无需重新加载/重新启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3832959/

相关文章:

php - 记录未从 android 插入到 mysql 数据库表

CSS 布局 : align elements in the right order

java - 无法使该网格正确对齐

java - 在模拟器中运行 Android 应用程序时没有布局

java - Manifest 文件中有多个元数据

android - 使用新适配器更新 recyclerview

android - React Native Android 状态栏图标颜色

java - 如何在 Eclipse 中使用 Windowbuilder 填充 JTable? (参见 GUI 的屏幕截图)

android - 如何在 android 2.2 中隐藏 Activity GUI

user-interface - Blackberry用户界面设计-可自定义的UI?