for the first time I\'m using the new Android\'s widget TextInputLayout, it\'s very nice but I\'m facing some problem using setError method
this is my xml
got solution for only setError in this link
i.e. i have used custom TextInputLayout
this is my custom TextInputLayout
but if i set length limit to TextInputLayout i.e.
app:counterEnabled="true"
app:counterMaxLength="35"
the color still shows when limit exceeds and also changes color to pink
so i build one solution for it used addTextChangedListener to that edit text and set background by code
code snippet
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() == 0) {
textInputLayout.setErrorEnabled(true);
textInputLayout.setError("Input should not be empty!");
} else {
textInputLayout.setErrorEnabled(false);
}
}
@Override
public void afterTextChanged(Editable s) {
setBackgroundToEt(editText);
}
});
private void setBackgroundToEt(EditText editText) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
editText.setBackground(getResources().getDrawable(R.drawable.edittext_background));
}
}
and inside validation method in the end, i have again used set background to my editText
code snippet:
private boolean validateInputs() {
//validation code...
setBackgroundToEt(editText);
}