我想将应用程序中的所有数字格式化为阿拉伯数字(١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩),因此我考虑将语言环境设置为阿拉伯语和地区的组合:埃及,而不仅仅是阿拉伯语,但不幸的是由于或其他原因,未设置区域设置。
我像这样设置我的区域设置:
Locale myLocale = new Locale("ar_EG");
Locale.setDefault(myLocale);
Configuration config = new Configuration();
config.locale = myLocale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
我的 strings.xml 放在名为“values-ar-rEG”的文件夹中。
我错了什么?
提前非常感谢您。
最佳答案
Locale 类可以接收 1,2 或 3 个参数,但最好使用 2 个参数(语言、国家/地区)来更改文本和数字格式以及从右到左语言的方向(即)。
我是这样解决的:
Locale myLocale = new Locale("ar","EG");
Locale.setDefault(myLocale);
Resources res = getApplicationContext().getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.setLayoutDirection(myLocale);
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
关于android - 在 Android 中,如何将区域设置设置为语言和区域的组合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48177031/