问题
I am using TextInputLayout from com.android.support:design:23.3.0
When I first apply an error it is shown correctly.
mInputPassword.setError(getString(R.string.error_invalid_password));
mInputEmail.setError(getString(R.string.error_field_required));
On the next login attempt I clear the error.
mInputEmail.setError(null);
mInputPassword.setError(null);
Then I run the validation and set the error again using the same code as above but this time the red line is applied but the error text is missing.
Anyone have any ideas on why this might be happening or have experienced similar situations?
I saw something similar reported here but it is for an older version of the design library and don't know if it is still a issue in the verison I am using,
回答1:
You simply has to do these steps:
setErrorEnabled(true);
setError("error");
for clearing:
setError(null);
setErrorEnabled(false);
repeat the first step to set a new error. setError(null)
clears the error message and icon, so I think the view to show is simply gone and setErrorEnabled(false)
will reset it.
回答2:
You are clearing the Error Message String:
mInputEmail.setError(null);
mInputPassword.setError(null);
So when you rerun the validation, you will get a blank string.
If you want the error message to go away, clear the erroneous text from the textview:
mInputEmail.setText("");
mInputPassword.setText("");
来源:https://stackoverflow.com/questions/36912602/textinputlayout-not-showing-error-message-after-clearing