How can I disable a view behind my SlidingDrawer in Android? How can I disable a view behind my SlidingDrawer in Android? android android

How can I disable a view behind my SlidingDrawer in Android?


Here's a way to get around this problem (I needed a solution also) - grab the linearLayout that holds the contents and add a click listener. Have the click listener respond to clicks (throw away, whatever) - and this then stops it propagating to the view below the sliding drawer - it works for me - and it doesn't block the other items in the drawer.


In side Layout do android:clickable="true"

For Example Following file is drawer.xml

Inside LinearLayout android:id="@+id/drawer_view" clickable="true"

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:tools="http://schemas.android.com/tools"        android:id="@+id/drawer_layout"        android:layout_width="match_parent"        android:layout_height="match_parent"        tools:context=".MainActivity">        <FrameLayout            android:id="@+id/container"            android:layout_width="match_parent"            android:layout_height="match_parent">        </FrameLayout>              <LinearLayout            android:id="@+id/drawer_view"            android:layout_width="@dimen/navigation_drawer_width"            android:layout_height="match_parent"            android:orientation="vertical"            android:layout_gravity="start"            android:clickable="true"            android:background="@color/drawer_background">            <LinearLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:padding="10dp"                android:background="@drawable/order_list_selector"                android:orientation="horizontal">                <ImageView                    android:layout_width="@dimen/user_image_w_h"                    android:layout_height="@dimen/user_image_w_h"                    android:scaleType="fitCenter"                    android:id="@+id/drawerUserImage"                    android:src="@drawable/ic_user_icon"                    android:layout_gravity="center_vertical" />                <LinearLayout                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:gravity="center"                    android:layout_gravity="center_vertical"                    android:orientation="vertical"                    android:layout_marginLeft="5dp"                    android:padding="5dp">                    <TextView                        android:id="@+id/drawerUserNameTextView"                        android:layout_width="match_parent"                        android:layout_height="wrap_content"                        android:text="Mansukh Ahir"                        android:textColor="@android:color/black"                        android:textSize="@dimen/font_large" />                    <TextView                        android:id="@+id/drawerEmailIdTextView"                        android:layout_width="match_parent"                        android:layout_height="wrap_content"                        android:textSize="@dimen/font_very_small"/>                </LinearLayout>            </LinearLayout>            <View                android:layout_width="fill_parent"                android:layout_height="1dp"                android:background="@color/holo_gray_light" />            <ListView                android:id="@+id/drawerListSlideMenu"                android:layout_width="wrap_content"                android:layout_height="fill_parent"                android:choiceMode="singleChoice"                android:dividerHeight="1dp" />        </LinearLayout>    </android.support.v4.widget.DrawerLayout>


Joe's answer did not do the trick for me. My scenario is a bit diferent. I have a FrameLayout with two children. Only one of the children has to be 'active' at a given moment, and while the second is active the first should no longer process any input. My solution:

    public static void changeVGstate(ViewGroup current, boolean enable){    current.setFocusable(enable);    current.setClickable(enable);    current.setEnabled(enable);    for (int i = 0; i < current.getChildCount(); i++)    {        View v = current.getChildAt(i);         if (v instanceof ViewGroup)            changeVGstate((ViewGroup)v, enable);        else        {            v.setFocusable(enable);            v.setClickable(enable);            v.setEnabled(enable);        }    }}

Enjoy!