Android TextInputLayout Autofill

104 views Asked by At

I am developing an android app, I've used TextInputLayouts to take input from user, while testing it on api level 24 it doesn't cause any problem but when i tried to test it on latest phones some textinputlayouts enables autofill option on phone and when user selects from autofill all other textinputlayouts fills with the same autofill content. Below are two TILs with same attributes

       <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/userInput_personalEmail_relationship_TIL"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/userInput_personalEmail_relationship_hint"
            app:endIconDrawable="@drawable/ic_info"
            app:endIconMode="custom">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/userInput_personalEmail_relationship_ET"
                style="@style/textInputEditText" />

        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/userInput_personalEmail_occasion_TIL"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/userInput_personalEmail_occasion_hint"
            app:endIconDrawable="@drawable/ic_info"
            app:endIconMode="custom">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/userInput_personalEmail_occasion_ET"
                style="@style/textInputEditText" />

        </com.google.android.material.textfield.TextInputLayout>

the first til with id relationship doesn't get autofill when user tries to enter text but the TIL with id occasion gets it and if user selects from autofill it fill all the autofill with same content from autofill user chose One thing to note that autofill suggests only email

What i am doing wrong?

I tried the attribute android:importantForAccessibility="no" but its not working

1

There are 1 answers

0
ryankuck On

From the docs we can see auto fill for Android is for the users personal info that they might type in the same across many apps and websites. This includes things like country code, phone number, home address, and in your case email.

For your use case you have a “relationship” email and an “occasion” email and it seems like they are supposed to be different and one or both are not the users personal email.

Basically what’s happening is a feature not a bug, where for example if there was an email and confirm email field, they both populate with the auto fill, or same thing with a password.

You can get around this with a custom component like in this question’s answer though: Android autofill enters the same info multiple times, when reusing layout

 override fun autofill(value: AutofillValue?) {
    if (hasFocus()) {
        super.autofill(value)
    }
}

Here the component will only auto fill when in focus. Hope that helps!