After updating some of our devices to android 8.0 , upon focusing on a TextInputEditText
field inside of a TextInputLayout
, the app crashes with th
If anyone still wants "hint" in "TextInputEditText" make app:hintEnabled="false" in TextInputLayout
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="password"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
I ran into this too. It turns out the issue was caused by setting the hint text on the EditText
nested inside the TextInputLayout
.
I did some digging and found this nugget in the 26.0.0 Beta 2 release notes. Android Support Release Notes June 2017
TextInputLayout must set hints on onProvideAutofillStructure()
That led me to try setting the hint on the TextInputLayout
instead of the nested EditText
.
This resolved the crashing issue for me. Example:
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Some Hint Text"
android.support.design:hintAnimationEnabled="true"
android.support.design:hintEnabled="true"
android.support.design:layout_marginTop="16dp">
<android.support.design.widget.TextInputEditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
I posted this as an answer here as I mixed up bookmarks. Sorry for posting the same answer twice.
@Luke Simpson is right. You can use it in themes.XML like:-
<item name="editTextStyle">@style/AppEditTextStyle</item>
and then put
<style name="AppEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:importantForAutofill">auto</item>
</style>
in V26/app_styles.xml
But, I had to put empty tag also in app_styles.xml in the default folder. Otherwise, all the properties of Edit text were getting overriding by this and my edit text was not working properly. And when you put importantForAutoFill property for v26 and you want autofill to work in 8.1, you can simply put
<style name="AppEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:importantForAutofill">auto</item>
</style>
So, autofill property works in 8.1. It will be disabled just for 8.0 as the crash is hapenning in 8.0 and it has already been fixed in 8.1.
I used the v26/themes.xml to override the EditText style autofill only for Oreo 8.0.0:
<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:importantForAutofill">noExcludeDescendants</item>
</style>
Note that I had to apply the style inline for each EditText in my layout xml for it to take effect. I tried to apply this change globally in my app theme but it didn't work for some reason.
// HAD TO DO THIS IN LAYOUT XML FOR EACH EDIT TEXT
<EditText
style="@style/EditTextStyle"
... />
// THIS DIDN'T TAKE EFFECT IN THEMES XML (HAS BEEN ADDED TO MANIFEST)
<style name="APP_THEME" parent="@style/Theme.AppCompat.Light">
<item name="android:editTextStyle">@style/EditTextStyle</item>
<item name="editTextStyle">@style/EditTextStyle</item>
</style>
Add below mentioned attribute in your EditText
:
android:importantForAutofill="noExcludeDescendants"
You can set any value for importantForAutofill with a style or in the XML it's fix for NPE when you focus the EditText but it's not fix if your long press the EditText and you click on AutoFill. I found a Bug Report about this bug here, please add a star and share your observations in the bug report also.
Thx.