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

后端 未结 5 1970
后悔当初
后悔当初 2021-01-01 16:56

I have a SlidingDrawer that pops up from the bottom of the screen and fills the screen about 80%. Even though the SlidingDrawer view is in focus, it is still possible to cli

相关标签:
5条回答
  • 2021-01-01 17:14

    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!

    0 讨论(0)
  • 2021-01-01 17:23

    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.

    0 讨论(0)
  • 2021-01-01 17:23

    I don't know if this will work, but it's worth a try. Call setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS) on your container View (the one that the sliding drawer slides over).

    0 讨论(0)
  • 2021-01-01 17:24

    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>
    
    0 讨论(0)
  • 2021-01-01 17:37

    I've tried to put SlidingDrawer in the RelativeLayout, instead of LinearLayout. And set mySlidingDrawer.bringToFront() in opening method.

    So I think this may be a solution.

    0 讨论(0)
提交回复
热议问题