首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android设置Textview和EditText区域设置

Android设置Textview和EditText区域设置
EN

Stack Overflow用户
提问于 2017-02-16 16:51:56
回答 2查看 4.6K关注 0票数 1

我正在构建一个应用程序,在该应用程序中,我明确地将应用程序的区域设置为阿拉伯语。然而,我想收集英语的电话号码。如何将EditText和TextView的地区显式设置为美国英语

下面是我如何设置应用程序区域设置。我有这个帮助者班

代码语言:javascript
复制
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中使用了这个助手,如下所示:

代码语言:javascript
复制
@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(LocaleHelper.wrap(newBase, "ar"));
}

如何将EditText或TextView的区域设置为US

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-02-18 09:38:55

问题是,应用于EditText的自定义字体没有英语数字,只有阿拉伯数字,因此无论我尝试了什么,只有阿拉伯数字才会出现,这是有意义的。

票数 0
EN

Stack Overflow用户

发布于 2017-10-29 12:07:30

您可以使用String.format()Locale.ENGLISH来显示英文数字而不是阿拉伯数字。

示例

代码语言:javascript
复制
String txtPrice = String.format(Locale.ENGLISH, "%d", item.getPrice());
mItemPriceTextView.setText(txtPrice);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42280096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档