There is such a field:

enter image description here

The default icon is a gray envelope. onTextChanged hung on the field, changing the icon when the entered email becomes valid. If the value is valid, onTextChanged changes the icon and the external flag isEmailCorrect . If not valid, returns a gray icon. When isEmailCorrect becomes true, the user can start validationSuccess() on the button, which in case of failure will cause the setError() field with the third picture.

The problem is that if the user fails the check, then the field icon will stop changing with successful validation, as if onTextChanged stopped working.

If shorter: after validationSuccess() field icon does not change with user input. Please help.


UPD : entering valid email after performing validationSuccess() , the code in the if branch of onTextChanged is executed. That is, the value passes the test correctly. It feels as if, after validationSuccess() stops working:

 binding.textAuthorizationEmail.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_email_correct, 0); 

Field:

 binding.textAuthorizationEmail.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 (binding.textAuthorizationEmail.getText().length() != 0 && Utility.isValidEmail(String.valueOf(binding.textAuthorizationEmail.getText()))) { binding.textAuthorizationEmail.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_email_correct, 0); isEmailCorrect = true; } else { binding.textAuthorizationEmail.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_email, 0); binding.buttonAuthorizationSend.setBackgroundColor(Color.GRAY); isEmailCorrect = false; } } @Override public void afterTextChanged(Editable s) { } }); 

validationSuccess ()

  public boolean validationSuccess() { boolean isSuccess = true; if (binding.textAuthorizationEmail.getText().length() == 0) { binding.textAuthorizationEmail.setError(getString(R.string.error_validation_empty), getErrorIcon(this, R.drawable.ic_email_error)); isEmailCorrect = false; isSuccess = false; } else if (!Utility.isValidEmail(String.valueOf(binding.textAuthorizationEmail.getText()))) { binding.textAuthorizationEmail.setError(getString(R.string.error_validation_email), getErrorIcon(this, R.drawable.ic_email_error)); isEmailCorrect = false; isSuccess = false; } return isSuccess; } 

Xml:

  <android.support.design.widget.TextInputLayout android:id="@+id/text_authorization_email_wrapper" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/margin_medium" android:layout_marginTop="@dimen/margin_ultra_big" android:layout_marginEnd="@dimen/margin_medium" android:hint="@string/hint_email" android:theme="@style/TextLabel"> <EditText android:id="@+id/text_authorization_email" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_email" android:gravity="start" android:inputType="textEmailAddress" /> </android.support.design.widget.TextInputLayout> 

@ style / TextLabel

 <style name="TextLabel" parent="TextAppearance.AppCompat"> <!-- Hint color and label color in FALSE state --> <item name="android:textColorHint">@color/color_grey</item> <!-- Label color in TRUE state and bar color FALSE and TRUE State --> <item name="colorAccent">@color/colorPrimary</item> <item name="colorControlNormal">@color/color_grey</item> <item name="colorControlActivated">@color/colorPrimary</item> <item name="android:textColorHighlight">@android:color/transparent</item> <item name="android:textColorLink">@android:color/transparent</item> </style> 
  • Tried to change the text when making .setError (null)? In fact, when the user starts editing the e-mail, the error must be reset. - virex-84
  • Tried (in all redefined methods), did not lead to success. - KirstenLy

1 answer 1

I decided myself by:

binding.textAuthorizationEmail.setCompoundDrawables(null,null,null,null);

in onTextChanged .

Do not ask me how this solves the problem, I have no idea. =)