Search code examples
androidandroid-layoutnavigation-drawerdrawerlayout

Drawer Layout takes the touch event instead of navigation pane's elements


My android project contains 2 navigation drawers. One from right side, other from left. It open with click of button using this:

if (mDrawerLayout.isDrawerOpen(mRightDrawerView))
    mDrawerLayout.closeDrawer(mRightDrawerView);
mDrawerLayout.openDrawer(mLeftDrawerView);

Both drawers have custom layouts in them, defined using:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<include
    android:id="@+id/left_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    layout="@layout/menu_panel" />

<include
    android:id="@+id/right_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    layout="@layout/search_panel" />

</android.support.v4.widget.DrawerLayout> 

The problem is: When I open a drawer and try to capture its click event, (There are buttons and textviews in the drawer layout) the drawer closes instead of responding to click events.

I have also used:

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerLayout.requestDisallowInterceptTouchEvent(true);

I do not want drawer to close on touch event inside it.

I have also tried changing the "clickable" attribute of drawer layout. But no use.

Any help is highly appreciated. Thanks


Solution

  • Might be its too late to answer your Question , but it'll help the others , those who are facing the same problem as you..

    Set Clickable 'true' to your included layouts i.e your left and right drawer. the clickable event consumes the touch.

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    <include
        android:id="@+id/left_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:clickable="true"
        layout="@layout/menu_panel" />
    
    <include
        android:id="@+id/right_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:clickable="true"
        layout="@layout/search_panel" />
    
    </android.support.v4.widget.DrawerLayout>