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

前端 未结 10 1549
囚心锁ツ
囚心锁ツ 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:39

    I create a custom view for avoiding repeated code and override setError method.

        public class UserInputView extends TextInputLayout {
    
            public UserInputView(Context context) {
               this(context, null);
            }
    
            public UserInputView(Context context, AttributeSet attrs) {
                this(context, attrs, 0);
            }
    
            public UserInputView(Context context, AttributeSet attrs, int defStyleAttr) {
                super(context, attrs, defStyleAttr);
            }
    
            @Override
            public void setError(@Nullable CharSequence error) {
                boolean isErrorEnabled = error != null;
                setErrorEnabled(isErrorEnabled);
                super.setError(error);
            }
    
         }
    

提交回复
热议问题