【发布时间】:2013-11-14 22:36:36
【问题描述】:
我创建了一个双语(有两种语言)android 应用程序。我在两个文件中插入了我的资源字符串:
For Persian language (default)
values/strings_locale.xml
For English language
values-en/strings_locale.xml
我第一次启动 Activity 我插入了以下代码:
Configuration c = new Configuration(this.getResources().getConfiguration());
c.locale = new Locale("fa_IR");
this.getResources().updateConfiguration(c, this.getResources().getDisplayMetrics());
所以在这段代码之后,我的默认语言将是波斯语,并且所有活动中的所有字符串都以波斯语正确显示。
但问题是当设备的屏幕旋转时,所有的字符串都以英文显示,并且所有其他活动也会发生这种情况!我必须关闭并重新打开我的应用程序。
为什么会发生这种情况以及如何解决这个问题?
【问题讨论】:
-
检查this documentation,当activity在旋转后重新创建时,你上面的代码可能不会再次运行...确保将代码放在可能再次处理之后的位置旋转。
标签: android localization internationalization rotation screen