I have a TextInputLayout with an EditText inside it.
This is my xml:
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Text" />
</android.support.design.widget.TextInputLayout>
My java code:
((TextInputLayout) findViewById(R.id.textInputLayout)).setError("ERROR");
When I call setError("ERROR"), the and the label(hint) color and EditText's bottom line color gets changed to red and the error appears. This is the behaviour that I expect.
Now let's say I do not call setError(null) before destroying my activity. Now I open the same activity again. I can see that the bottom line remains red for all EditText fields inside in my application, although the label colour seems to be reset and the error message is dismissed. This is not always reproducible, but if I keep trying, I can eventually get it.
I am using a Nexus 4 with 5.1.1.
Am I doing something wrong?
This is due to a bug in the AppCompat library.
Reported by [email protected], Oct 19, 2015 Using design support library 23.1.0
Steps to reproduce the problem (including sample code if appropriate).
- SetError on one TIL (i.e. in a form)
- The TIL has a red underline (ok)
- Navigate back and enter the activity again. Or go to another Activity with TILs.
What happened.
- All the TILs have a red underline, even in other Activities. (but no error text).
- The red underlines disappear only after force closing the app.
Also reported here:
Issue status was changed to FutureRelease
on 11 Nov 2015, so we can hope for a fix coming soon.
In the meantime, it seems there are 3 workarounds:
EditText
to the top of your layoutEditText
editText.setBackground(editText.getBackground().getConstantState().newDrawable())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With