“缺少 autofill 提示属性”

我对 Palette -> Text有意见
当我想设置一些视图时,我收到一个消息问题 "Missing autofillHints attribute"
有什么建议吗?

114382 次浏览

也许你正在使用 EditText。在 API 26及以上版本中, autofillHints 用于填充空的 EditText,它实际上是在建议应该在其中放置哪种类型的内容。

只要加上:

android:autofillHints="username" // the type of content you want

你的 EditText和警告将消失。

您可以使用新的 android:autofillHints属性来说明这一点 和 告诉 autofill你想要的视图(或者 不想)被填满。

阅读: http://medium.com/@bherbst/getting-androids-autofill-to-work-for-you-21435debea1”rel = “ noReferrer”> https://medium.com/@bherbst/getting-androids-autofill-to-work-for-you-21435debea1

而这个: < a href = “ https://developer.android.com/guide/questions/text/autofill-services”rel = “ norefrer”> https://developer.android.com/guide/topics/text/autofill-services


编辑:

然而,你可以设置:

android:importantForAutofill="no"

要告诉组件填写并排除错误并不重要。

如果你不想要 autofillHints

MinSdk > = 26 .

Should use android:importantForAutofill=no if you don't want autofill hint

<EditText
android:importantForAutofill="no"/>

minSdk<26

添加 android:importantForAutofill然后 tools:targetApi使 IDE 不这个关于 API 级别的警告

<EditText
android:importantForAutofill="no"
tools:targetApi="o"
/>

如果你想要 autofillHints

即使我们没有设置 autofillHints属性,默认情况下也会启用自动填充服务。指定一个自动填充提示将帮助自动填充服务工作更好地像我们的期望。见 文件

MinSdk > = 26

  • 只需要添加 android:autofillHints="{a contant value}"(例如: "android:autofillHints="password")(使用来自 给你的常数)

minSdk<26, add tools:targetApi to make IDE don't this warning

    <EditText
android:autofillHints="emailAddress"
tools:targetApi="o"/>

注意

  • autofillHints and importantForAutofill only used in API 26 and higher but we still can use it in API < 26 without crash (你可以在这个答案中看到) (it don't crash but ofcourse it don't have any effect with API < 26)

  • tool:...只是用来使 IDE 不发出警告,它不会影响应用程序运行时的任何东西,所以 tools:ignore="Autofill不会帮助你隐藏自动填充提示

你需要在 Xml文件中启用字符串文本,例如:

<string name="editText2">Name</string>.

然后你需要启用 activity_mail.xml-然后启用 自动填充提示活动,方法是:

android:hint="@string/editText2"