TextInputLayout.setError() leaves empty space after clearing the error

前端 未结 10 1557
囚心锁ツ
囚心锁ツ 2020-12-08 09:24

I recently used TextInputLayout and it\'s setError() method. The problem I\'m getting is, when I clear the error by calling setError(null)

10条回答
  •  醉话见心
    2020-12-08 09:54

    The following code works fine

        textInputLatout.getEditText().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() < 1) {
                   textInputLayout.setErrorEnabled(true);
                    textInputLayout.setError("Please enter a value");
                }
    
                if (s.length() > 0) {
                    textInputLayout.setError(null);
                    textInputLayout.setErrorEnabled(false);
                }
    
            }
    
            @Override
            public void afterTextChanged(Editable s) {
    
            }
        });
    

提交回复
热议问题