Reputation: 1305
I am using EditText with TextInputLayout. This is the code, that I am using to display error.
private boolean validateEmail() {
String email = inputEmail.getText().toString().trim();
if (email.isEmpty() || !isValidEmail(email)) {
inputLayoutEmail.setErrorEnabled(true);
inputLayoutEmail.setError(getString(R.string.err_msg_email));
requestFocus(inputEmail);
return false;
} else {
inputLayoutEmail.setErrorEnabled(false);
}
return true;
}
I am calling this method in edittext's textwatcher like in this link http://www.androidhive.info/2015/09/android-material-design-floating-labels-for-edittext/
Once I entered a valid input then clear that ,it will show error message as expected,But it wont work if i enter the text again and then clear it again.ie.It is not showing any error message.
I am using compile 'com.android.support:design:23.1.0'
library.
inputLayoutEmail.setErrorEnabled(true);
is calling but error is not displaying. What might be the problem? How I can solve this?
Upvotes: 8
Views: 12401
Reputation: 761
I was having same issue and i was using data binding so adding below line solved my issue : app:errorEnabled="true"
Upvotes: 1
Reputation: 14192
In your layout file, ensure you have layout_height="wrap_content"
for the TextInputLayout
instead of a dimension. This was causing the issue for me.
Upvotes: 49
Reputation: 71
You just need apply,
inputLayoutEmail.setErrorEnabled(false);
inputLayoutEmail.setError(null);
It worked for me. Hope it will work for you too.
Upvotes: 7
Reputation: 3563
Use Android Support Library, revision 23.4.0 (May 2016)
Fixed an issue where TextInputLayout
doesn't clear error tint after setErrorEnabled(false)
on API level 21 - 22 (Issue 202829)
Upvotes: 0
Reputation: 418
The example worked for me.
you use
compile 'com.android.support:design:23.1.0'
and the right one is
compile 'com.android.support:design:23.0.1'
Upvotes: 3