您的代码似乎没问题,但是,自动填充可能无法按预期工作的原因可能有几个:
尝试在 XML 中设置输入类型:
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAutofill="yes"
android:inputType="textEmailAddress"
android:minWidth="200dp"
app:layout_constraintBottom_toTopOf="@id/password"
app:layout_constraintStart_toStartOf="@id/password" />
您可以尝试为每个字段使用单个特定的自动填充提示。
您正在使用AUTOFILL_HINT_USERNAME。您也可以尝试在用户名字段中使用 AUTOFILL_HINT_GENERIC 或 AUTOFILL_HINT_TEXT 看看是否有任何影响