conf.setLocale() 的不一致行为
Inconsistent behaviour of conf.setLocale()
根据给定的 solution,我使用以下代码以编程方式更改语言:
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
if (Build.VERSION.SDK_INT >= 17) {
conf.setLocale(newLocale);
} else {
conf.locale = newLocale;
}
res.updateConfiguration(conf, dm);
我在 onCreate()
在 setContentView()
之前和 super.Oncreate()
之后的每个 activity 中调用它。
conf.setLocale()
内部调用setLayoutDirection()
并且应该根据指定的locale
更改布局方向。但它的行为并不一致。布局方向经常被系统覆盖。解决方法应该是什么?
如有任何帮助,我们将不胜感激。
似乎是通过应用程序的 context
获取资源导致了这种不一致的行为。使用 activity 中的 getResources()
可以解决问题。
根据给定的 solution,我使用以下代码以编程方式更改语言:
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
if (Build.VERSION.SDK_INT >= 17) {
conf.setLocale(newLocale);
} else {
conf.locale = newLocale;
}
res.updateConfiguration(conf, dm);
我在 onCreate()
在 setContentView()
之前和 super.Oncreate()
之后的每个 activity 中调用它。
conf.setLocale()
内部调用setLayoutDirection()
并且应该根据指定的locale
更改布局方向。但它的行为并不一致。布局方向经常被系统覆盖。解决方法应该是什么?
如有任何帮助,我们将不胜感激。
似乎是通过应用程序的 context
获取资源导致了这种不一致的行为。使用 activity 中的 getResources()
可以解决问题。