如何在TextInputLayout中设置错误endicon,该错误在出现错误时显示,在没有错误时消失

时间:2019-07-06 11:01:50

标签: java android

我想在TextinputLayout中设置显示错误发生时的错误endicon。我该怎么办?

Emailtext.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
                if(charSequence.length()<5)
                {
                  EmailLayout.setError("Error is occur");
                  EmailLayout.setEndIconDrawable(R.drawable.baseline_info_black_48);
                  EmailLayout.setEndIconActivated(true);
                  EmailLayout.setEndIconContentDescription("Error icon");

                }
                else
                {

                    EmailLayout.setErrorEnabled(false);
                }

            }

1 个答案:

答案 0 :(得分:0)

在其他情况下,

EmailLayout.setError(null);