Eri*_* S. 6 android locale country-codes
塞尔维亚语有拉丁字母和西里尔字母。在 Android 的日期和时间选择器小部件中,显示的塞尔维亚语言区域字母似乎是西里尔字母,如此处所示。
我想更改区域设置,以便 Android 小部件使用拉丁塞尔维亚字母。
当前的语言/国家代码(产生西里尔字母)分别是sr和RS。因此,我的 setLocale 函数被称为
setLocale("sr", "RS");
Run Code Online (Sandbox Code Playgroud)
这是我不确定的部分 - 根据localeplanet.com,拉丁塞尔维亚语的本地代码是sr_Latn_RS。但是,我都尝试过
setLocale("sr_Latn", "RS");
//and
setLocale("sr_Latn_RS", "RS");
Run Code Online (Sandbox Code Playgroud)
两者都不起作用(没有变化,默认为英语)。根据 Android 文档,setLocale 似乎需要两个字母代码。
语言代码是 ISO 639-1 定义的两个字母的小写 ISO 语言代码(例如“en”)。国家/地区代码是 ISO 3166-1 定义的两个字母大写 ISO 国家/地区代码(例如“US”)。变体代码未指定。
那么如何指定拉丁塞尔维亚语区域设置代码?或者它不存在?
Hir*_*tel -1
您可以使用下面的一个吗?
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Resources res = this.getResources();
Configuration conf = res.getConfiguration();
boolean isLatinAlphabet = PreferenceManager.getDefaultSharedPreferences(this);
if(conf.locale.getLanguage().equals("sr") && isLatinAlphabet) {
conf.locale = new Locale("sr", "YourContryCode");
res.updateConfiguration(conf, res.getDisplayMetrics());
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意:更换您的YourContryCode在线conf.locale = new Locale("sr", "YourContryCode");。
清单.xml:
<application
android:name=".MyApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/application_name"
android:theme="@style/AppTheme">
...
</application>
Run Code Online (Sandbox Code Playgroud)
希望对你有帮助。
| 归档时间: |
|
| 查看次数: |
9076 次 |
| 最近记录: |