我正在构建一个应用程序,在该应用程序中,我明确地将应用程序的区域设置为阿拉伯语。然而,我想收集英语的电话号码。如何将EditText和TextView的地区显式设置为美国英语。
下面是我如何设置应用程序区域设置。我有这个帮助者班
public class LocaleHelper extends ContextThemeWrapper {
public LocaleHelper(Context base) {
super(base, R.style.MyTheme);
}
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context, String language) {
Configuration config = context.getResources().getConfiguration();
if (!language.equals("")) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setSystemLocale(config, locale);
} else {
setSystemLocaleLegacy(config, locale);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLayoutDirection(locale);
context = context.createConfigurationContext(config);
} else {
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
}
}
return new LocaleHelper(context);
}
@SuppressWarnings("deprecation")
private static Locale getSystemLocaleLegacy(Configuration config) {
return config.locale;
}
@TargetApi(Build.VERSION_CODES.N)
private static Locale getSystemLocale(Configuration config) {
return config.getLocales().get(0);
}
@SuppressWarnings("deprecation")
private static void setSystemLocaleLegacy(Configuration config, Locale locale) {
config.locale = locale;
}
@TargetApi(Build.VERSION_CODES.N)
private static void setSystemLocale(Configuration config, Locale locale) {
config.setLocale(locale);
}
}在我的活动中,我在attachBaseContext中使用了这个助手,如下所示:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleHelper.wrap(newBase, "ar"));
}如何将EditText或TextView的区域设置为US?
发布于 2017-02-18 09:38:55
问题是,应用于EditText的自定义字体没有英语数字,只有阿拉伯数字,因此无论我尝试了什么,只有阿拉伯数字才会出现,这是有意义的。
发布于 2017-10-29 12:07:30
您可以使用String.format()和Locale.ENGLISH来显示英文数字而不是阿拉伯数字。
示例
String txtPrice = String.format(Locale.ENGLISH, "%d", item.getPrice());
mItemPriceTextView.setText(txtPrice);https://stackoverflow.com/questions/42280096
复制相似问题