129

I have an issue with Palette -> Text
When I want to set some view, I receive a message problem "Missing autofillHints attribute"
Any suggestions?

Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88
Sebastian
  • 1,339
  • 3
  • 7
  • 6

4 Answers4

140

Perhaps you are using an EditText. autofillHints is used in API 26 and above for filling empty EditTexts and it's actually suggesting which type of content should be placed in there.

Just add :

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

To your EditText and warning will disappear.

You do this using the new android:autofillHints attribute to tell autofill what type of content you expect, and android:importantForAutofill to tell autofill which views you want (or do not want) to be filled.

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

And this: https://developer.android.com/guide/topics/text/autofill-services


Edit:

You can however set:

android:importantForAutofill="no"

To the component to tell it is not important to fill and get rid of the error.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
112

If you don't want autofillHints

minSdk>=26 .

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

<EditText
        android:importantForAutofill="no"/>

minSdk<26

Add android:importantForAutofill then tools:targetApi to make IDE don't this warning about API level

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

If you want autofillHints

Autofill service enable by default even if we don't set autofillHints attribute. specify an autofillHints will help autofill service work better like our expection. see documents here

minSdk>=26

  • Just need to add android:autofillHints="{a contant value}" (eg: "android:autofillHints="password") (use constant from here)

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

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

Note

  • autofillHints and importantForAutofill only used in API 26 and higher but we still can use it in API < 26 without crash (you can see in this answer) (it don't crash but ofcourse it don't have any effect with API < 26)

  • tool:... just use to make IDE don't warning, it will not effect anything when application running so tools:ignore="Autofill don't help you hide autofill hint

Linh
  • 57,942
  • 23
  • 262
  • 279
  • 2
    According to the documentation - https://developer.android.com/reference/android/view/View.html#setAutofillHints(java.lang.String...) - the `android:autoFillHints` constant for an email address is `emailAddress` rather than just `email`. – ban-geoengineering Apr 29 '20 at 12:17
  • @ban-geoengineering this comment was more useful for me than the entire answer. Thanks a ton – Kartik Jul 08 '20 at 07:15
  • This answer is better structured & more readable than the accepted one. – Touhid Aug 18 '20 at 18:52
0

you need to the strings.xml file and enable the string text in there, for example:

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

then you need to activity_mail.xml - and then enable the autofillhint activity there, by using:

android:hint="@string/editText2"
Hadi GhahremanNezhad
  • 2,377
  • 5
  • 29
  • 58
0

For me first, I wrote this but had error:

<EditText
    android:autofillHints="Name"
    ....../>

So I changed it in the form below and worked:

<EditText
    android:hint="Name"
    ....../>

You can always suppress it if you do not need with:

<EditText
    android:importantForAutofill="no"
    ....../>
Eick01
  • 1
  • 2