Disable DrawerLayout's scrim touch gesture

前端 未结 3 1066
我在风中等你
我在风中等你 2021-01-24 11:25

I need to disable touch gesture on the scrim (the red highlighted part). I want to dismiss the drawer only with the swipe.

The issue is that when the drawer lay

3条回答
  •  梦谈多话
    2021-01-24 11:59

    You have to create custom drawer for that like this

    public class CustomDrawer extends DrawerLayout {
    
    
    
        public CustomDrawer(Context context) {
            super(context);
    
        }
    
        public CustomDrawer(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
    
        }
    
        public CustomDrawer(Context context, AttributeSet attrs) {
            super(context, attrs);
    
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent event) {
            if(isDrawerOpen(Gravity.START)){
                if(event.getX() > getChildAt(1).getWidth()){
                    return false;
                }
            }
            return super.onInterceptTouchEvent(event);
        }
    
    }
    

    Note : getChildAt(1) should be that child to whom you have given gravity as "start" and whose width determines the width of opening drawer.

    I hope this should solve your problem

提交回复
热议问题