【问题标题】:Auto fill phone number without country code自动填写不带国家代码的电话号码
【发布时间】:2020-04-29 21:45:45
【问题描述】:

我有一个包含电话号码的编辑文本。

<androidx.appcompat.widget.AppCompatEditText
                   android:id="@+id/et_mobile_number"
                   style="@style/EditTextBoxNumeric"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:inputType="number"
                   android:maxLength="@integer/max_phone_number_length"
                   android:autofillHints="phoneNumberDevice"
                    />

Android 会尝试使用电话号码自动填充此编辑文本,但这样做时会连同国家代码一起填充。由于我对该编辑文本可以容纳的字符数设置了上限,因此删除了该数字的最后三位。

例如,编辑文本显示数字的自动填充选项(+91 77777 77890) 单击该选项后,编辑文本仅填充(+91 77777 777)。我需要的只是 (77777 77890) 而不是国家代码 (+91)。

我试过了

      binding.etMobileNumber.setAutofillHints(HintConstants.AUTOFILL_HINT_PHONE_NUMBER_DEVICE)
binding.etMobileNumber.setAutofillHints(HintConstants.AUTOFILL_HINT_PHONE_NATIONAL)

android:autofillHints="phoneNumberDevice"
android:autofillHints="phoneNational"

【问题讨论】:

    标签: android android-edittext androidx phone-number autofill


    【解决方案1】:

    电话号码使用AUTOFILL_HINT_PHONE_NATIONAL,不带国家代码

    binding.etMobileNumber.setAutofillHints(
        HintConstants.binding.etMobileNumber.setAutofillHints(HintConstants.AUTOFILL_HINT_PHONE_NATIONAL))
    

    在xml中phoneNational

    这是文档https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PHONE_NATIONAL

    【讨论】:

    • 这在我的测试代码中运行良好。尝试仅使用其中一个选项,xml 或 Java。不是都。我只在xml中使用过,它可以工作。
    • 嘿@Nishita 你有没有机会使用三星设备?我有一个 S10E,即使有电话国旗,我也能得到整个号码(带国家代码前缀)
    猜你喜欢
    • 1970-01-01
    • 2015-01-19
    • 2017-11-22
    • 2021-10-03
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多