【问题标题】:changing locale in app on Android 2.2 platform (on Android 4.0 is ok) in my case在我的情况下,在 Android 2.2 平台上更改应用程序中的语言环境(在 Android 4.0 上是可以的)
【发布时间】:2012-04-13 00:12:36
【问题描述】:

我想以编程方式更改我的应用语言环境。我使用下面的代码来完成在onCreate() Activity 方法中的任务:

@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);

    Resources res = context.getResources();
    DisplayMetrics dm = res.getDisplayMetrics();

    Configuration config= new Configuration();
    config.locale = new Locale("fr"); //use French locale
    res.updateConfiguration(config, dm);

    //following code will navigate among fragments
    ...
}

我的应用只有 一个 Activity,其中托管 几个片段

如果我在 Android 4.0 平台上运行我的应用程序,它运行良好,每个片段都以“法语”语言显示。

但是如果我在Android 2.2平台上运行,只有第一个片段以法语显示,下一个替换的片段仍然显示英文(我的手机设置使用英文区域设置) .

为什么它只适用于 Android 4.0 平台??

【问题讨论】:

    标签: android android-layout android-intent android-emulator android-widget


    【解决方案1】:

    这看起来像是 Android 2.x 中的一些错误

    因为如果你不是在onCreate() 而是在createMenu() 或在一些spinner.setOnItemSelectedListener() 中更改语言环境,它会起作用。

    这是一种解决方法,但尝试在启动您的应用并更改其中的区域设置后调用一些事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-26
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多