有效地更改应用程序中的语言环境

Changing locale within the app effectively

根据 this 的回答,我在每个 activity 的 onCreate() 方法中使用以下代码:

    Resources res = context.getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.setLocale(newLocale);
    res.updateConfiguration(conf, dm);

但这并不能有效地更新配置。需要解决以下问题:

  1. dialogs的布局方向好像被系统覆盖了,本来应该由conf.setLocale(newLocale)处理的。

  2. 一些小部件也是如此,例如TimePicker

  3. NumberPickerTimePicker 中的数字也被覆盖。

此处有效的方法应该是什么?

似乎 post 回答我的问题还为时过早,但是在上面的代码中添加 Locale.setDefault(newLocale) 可以解决所有提到的三个问题。