【问题标题】:"Missing autofillHints attribute"“缺少 autofillHints 属性”
【发布时间】:2021-07-02 11:14:55
【问题描述】:

我对@9​​87654321@ 有疑问
当我想设置一些视图时,我收到一个消息问题"Missing autofillHints attribute"
有什么建议么?

【问题讨论】:

  • tools:ignore="Autofill" 是目前唯一可以忽略的方法。

标签: android


【解决方案1】:

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

只需添加:

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

发送至您的EditText,警告将消失。

您可以使用新的android:autofillHints 属性来告诉 autofill 您期望的内容类型,以及 android:importantForAutofill 告诉 autofill 您想要哪些视图(或 不想)被填满。

阅读: https://medium.com/@bherbst/getting-androids-autofill-to-work-for-you-21435debea1

还有这个: https://developer.android.com/guide/topics/text/autofill-services


编辑:

但是你可以设置:

android:importantForAutofill="no"

向组件告诉填充和消除错误并不重要。

【讨论】:

  • 再次出现错误:(“缺少可访问性标签”“旧版本上未使用的属性”
  • 我可以看截图吗?之后它应该会消失。
  • 再次出现错误:(“缺少可访问性标签”“旧版本上未使用的属性”
  • 我是新人,所以我还不能发图片:(
  • 注意:"importantForAutofill" 仅用于 API 级别 26 及更高级别
【解决方案2】:

如果你不想要autofillHints

minSdk>=26 .

如果你不想要自动填充提示,应该使用android:importantForAutofill=no

<EditText
        android:importantForAutofill="no"/>

minSdk

添加 android:importantForAutofill 然后 tools:targetApi 使 IDE 不会出现有关 API 级别的警告

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

如果你想要autofillHints

即使我们没有设置autofillHints 属性,自动填充服务也会默认启用。指定一个 autofillHints 将帮助自动填充服务像我们预期的那样更好地工作。见documents here

minSdk>=26

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

minSdk,添加tools:targetApi让IDE不出现这个警告

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

注意

  • autofillHintsimportantForAutofill 仅在 API 26 及更高版本中使用,但我们仍然可以在 API you can see in this answer)(它不会崩溃,但当然它对 API 没有任何影响)

  • tool:... 只是用来让 IDE 不警告,它不会在应用程序运行时产生任何影响,所以tools:ignore="Autofill 不会帮你隐藏自动填充提示

【讨论】:

  • 根据文档 - developer.android.com/reference/android/view/… - 电子邮件地址的 android:autoFillHints 常量是 emailAddress 而不仅仅是 email
  • @ban-geoengineering 这个评论对我来说比整个答案更有用。非常感谢
  • 这个答案比接受的答案结构更好,可读性更强。
【解决方案3】:

您需要在 strings.xml 文件中启用字符串文本,例如:

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

然后你需要activity_mail.xml - 然后启用 autofillhint 活动,使用:

android:hint="@string/editText2"

【讨论】:

  • 问题没有解决办法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-25
相关资源
最近更新 更多