android - PhoneNumberFormattingTextWatcher 在 android MotoG 编辑文本中不起作用

标签 android android-edittext phone-number textwatcher country

在 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());

最佳答案

来晚了,但这肯定对 future 的观众有帮助。

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 上测试过。

关于android - PhoneNumberFormattingTextWatcher 在 android MotoG 编辑文本中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30501891/

相关文章:

java - 使用缓存和 ArrayAdapter 在 Android 应用程序上进行 JUnit 测试

java - 如果没有应用程序类,我收到此错误 android.app.Application 无法转换为 android.app.Activity

java - 错误: “Method getText() must be called from the UI thread, currently inferred thread is worker.”

android - Phone.IS_PRIMARY 未提供联系人 : Android 的主号码

objective-c - iOS 上的电话号码格式

android - 从硬件设备执行时如何查看代码错误

android - ActionBar 添加组件之间的间距

Android EditText 在最大长度时自动聚焦到下一个 EditText

android - 如何删除 EditText 的色调颜色或将其设置为 android 中的默认样式?

android - 以编程方式获取Android手机的电话号码