Search code examples
androidclickableslidingdrawerontouchlistener

Disabling layer under SlidingDrawer in Android


I've found a few questions on this topic and i've tried the solutions, but I can't seem to get it right. I have a TableLayout as the first child in a RelativeLayout and a SlidingDrawer as the second child. The slide works fine, but clicking on the drawer when it's open goes through to the items under the drawer.

I've tried adding an ontouch listener with a "return true" to the opening of the slider, but all that seems to do is not allow me to open the drawer. Also, anything that "would" be covered by the drawer if it was open, is unclickable.

If I change the "return true" to a

if (slidingDrawer.isOpened()) return true; else return false;

this gives me a couple of problems. While the drawer opens and i cannot click through to the lower layer, I also cannot click anything on the drawer or click the handle to close the drawer.

I'm not sure what I'm missing. I'd appreciate any help.


Solution

  • I finally got around this by doing the following type of thing:

    //sliderdrawer close
    private OnDrawerCloseListener onClick_DrawerClosed = new OnDrawerCloseListener() {
        @Override
        public void onDrawerClosed() {
            _slideDrawer.setClickable(false);
        }
    };
    
    //sliderdrawer open
    private OnDrawerOpenListener onClick_DrawerOpened = new OnDrawerOpenListener() {
        @Override
        public void onDrawerOpened() {
            _slideDrawer.setClickable(true);
        }
    };