自动填充不带国家/地区代码的电话号码



我有一个编辑文本,可以输入电话号码。

<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"

对不带国家/地区代码的电话号码使用AUTOFILL_HINT_PHONE_NATIONAL

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

在 xmlphoneNational

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

相关内容

最新更新