Android: Prevent DrawerLayout from passing touch events to views behind

Posted: December 23, 2015 in Android

I have an Android project using DrawerLayout, it’s working fine except that when touching on the empty area of the drawer, the touch events are caught by views behind.

To resolve it, you can add android:clickable=”true” to the drawer view.

<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/content_view" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    <FrameLayout android:id="@+id/drawer_view" android:layout_width="300dp" <strong>android:clickable="true"</strong> android:importantForAccessibility="no" android:layout_height="match_parent" android:layout_gravity="left"/>
</android.support.v4.widget.DrawerLayout>

But if your drawer view is included using fragment instead of framelayout, you need add the android:clickable=”true” to the root tag of the fragment layout xml.

Credit: http://stackoverflow.com/questions/18811973/android-how-do-i-keep-drawerlayout-from-passing-touch-events-to-the-underlying#comment43807569_19423579

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s