TextInputLayout setError method throws ClassCastException in 24.2.0

后端 未结 3 1151
感情败类
感情败类 2021-01-19 15:34

I updated support lib version to 24.2.0 and my registration screen is dead now. The problem is in the TextInputLayout, I have two methods:

    protected void         


        
3条回答
  •  一生所求
    2021-01-19 16:01

    The problem investigation showed that there is extra layout for some reason, so now we have TextInputLayout -> FrameLayout -> TextInputEditText and that is sad :( so as temp workaround I've created following method:

    @Nullable
    private TextInputLayout getTextInputLayout(@NonNull EditText editText) {
            View currentView = editText;
            for (int i = 0; i < 2; i++) {
                ViewParent parent = currentView.getParent();
                if (parent instanceof TextInputLayout) {
                    return (TextInputLayout) parent;
                } else {
                    currentView = (View) parent;
                }
            }
            return null;
    }
    

    This one will find your TextInputLayout in view hierarchy.

    If you the lucky one you will notice this pink error color change, the easy way to overcome it is override style, in styles.xml:

    
    

提交回复
热议问题