我遇到了与您类似的问题,请找到解决方案:
1- 确保您已将以下权限添加到清单中:
<uses-permission
android:name="android.permission.BIND_AUTOFILL_SERVICE"
tools:ignore="ProtectedPermissions" />
2- 假设在您的登录屏幕中您有三个EditText
(用户名、密码和验证码),因此您必须添加android:importantForAutofill
对于屏幕中的所有编辑文本。如果您错过添加它(例如,由于验证码而无需保存),不幸的是,自动填充对话框将不会显示。
3-要保存用户名和密码,您应该为用户名 editText 和密码 editText 添加:
android:importantForAutofill="yes"
对于用户名 editText 您应该添加:
android:autofillHints="username"
对于密码 editText 您应该添加:
android:autofillHints="password"
笔记:
你不应该使用textNoSuggestions
对于密码的文本输入类型:
android:inputType="textPassword|textNoSuggestions"
相反,您应该使用:
android:inputType="textPassword"
4-您应该排除不需要的editText(验证码),以免被保存,因此您应该添加到验证码editText:
android:importantForAutofill="noExcludeDescendants"
5-这是代码片段:
com.google.android.material.textfield.TextInputLayout
android:id="@+id/usernameTextInputLayout"
style="@style/TextInputStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_16"
android:layout_marginEnd="@dimen/margin_16"
android:layout_marginBottom="@dimen/margin_16"
app:endIconDrawable="@drawable/ic_username"
app:endIconMode="custom"
app:endIconTint="?attr/theme_primary">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="username"
android:hint="@string/hint_username"
android:imeOptions="actionNext"
android:importantForAutofill="yes"
android:inputType="text"
android:maxLines="1"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/passwordTextInputLayout"
style="@style/TextInputStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_16"
android:layout_marginEnd="@dimen/margin_16"
android:layout_marginBottom="@dimen/margin_16"
app:endIconDrawable="@drawable/ic_password"
app:endIconMode="custom"
app:endIconTint="?attr/theme_primary">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="password"
android:hint="@string/hint_password"
android:importantForAutofill="yes"
android:inputType="textPassword"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/captchaTextInputLayout"
style="@style/TextInputStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_16"
android:layout_marginEnd="@dimen/margin_16"
android:layout_marginBottom="@dimen/margin_16"
android:importantForAutofill="noExcludeDescendants"
app:boxCornerRadiusTopEnd="0dp"
app:boxCornerRadiusTopStart="0dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/captchaEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_captcha_input"
android:imeOptions="actionNext"
android:importantForAutofill="noExcludeDescendants"
android:inputType="numberDecimal"
android:maxLength="@integer/otp_input_length"
android:maxLines="1"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>