My need is the following: in a form, I have 7 fields and each one can be in error. When I lose focus on a field, I have to check if the data is valid and if not, change the TintColor for red.
The problem I got is the following: impossible to set the color to red.
After many and many tries, I finally realized why: my color change is override by the natural behaviour. What I really need is not "onFocusChange", but something like "AfterFocusChange" to be sure I have the last word about that color.
Sadly, it seems it doesn't exists. Do you have any idea how I can manage to do it?
Currently, my code looks like this:
@OnFocusChange(R.id.create_account_password)
public void onPasswordFocusLost(boolean focused) {
if (!focused) {
Matcher matcher = VALID_PASSWORD_REGEX.matcher(passwordField.getText());
isPasswordInError = !matcher.matches() || passwordField.getText().length() >= 8;
}
updateErrorDisplay(isPasswordInError, passwordField, passwordError, passwordRule);
}
and
private void updateErrorDisplay(boolean showError, EditText field, TextView error, TextView rule) {
if (showError) {
error.setVisibility(View.VISIBLE);
field.getBackground().setColorFilter(ContextCompat.getColor(this, R.color.red),
PorterDuff.Mode.SRC_ATOP);
if (rule != null) {
rule.setVisibility(View.VISIBLE);
}
} else {
error.setVisibility(View.GONE);
field.getBackground().clearColorFilter();
if (rule != null) {
rule.setVisibility(View.GONE);
}
}
}
Thanks!