【问题标题】:PhoneNumberFormattingTextWatcher is Not working in android MotoG Edit textPhoneNumberFormattingTextWatcher 在 android MotoG 中不起作用 编辑文本
【发布时间】:2015-05-28 09:02:37
【问题描述】:

在 android 中 phonenumberformattingtext watcher 不适用于 Moto-G Mobile ,但它在 (nexus -7, nexus-9, nexus-6 , nexus-4) 中运行良好,但在 Moto-G 中不起作用请帮忙。

我的代码是:

phoneNumber.addTextChangedListener(this);
phoneNumber.setFilters(new InputFilter[] { filter , new InputFilter.LengthFilter(14)});
alternativePhoneNumber.setFilters(new InputFilter[] { filter , new InputFilter.LengthFilter(14)});
phoneNumber.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
alternativePhoneNumber.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

【问题讨论】:

  • 您是否检查了您在语言设置中设置的语言区域设置?
  • 感谢 Anjali,它工作正常。
  • 遇到了同样的问题,但删除 android:digits="1234567890+" 后它就消失了。

标签: android android-edittext phone-number textwatcher country


【解决方案1】:

已经晚了,但这肯定会对未来的观众有所帮助。

mPhoneText.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

这不适用于 21 或更高版本的 api。所以你应该像这样包装 api lvl 条件。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mPhoneText.addTextChangedListener(new PhoneNumberFormattingTextWatcher("US"));
        }else {
            mPhoneText.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
        }

别忘了设置inputType="phone"

我在 moto g4 plus 中测试过。

【讨论】:

    【解决方案2】:

    检查您在手机语言设置中设置的语言区域...将其设置为英语(美国)。

    【讨论】:

      【解决方案3】:

      确保 android:inputType="phone" 在您的 xml 中设置在您的 TextView 上。

      【讨论】:

        猜你喜欢
        • 2013-01-27
        • 1970-01-01
        • 2016-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多