我遇到了与您的情况类似的问题,请找到解决方案:
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(Captcha)以免被保存,所以你应该添加到验证码editText:
android:importantForAutofill="noExcludeDescendants"
5- 这是代码的 sn-p:
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>