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

后端 未结 5 2155
后悔当初
后悔当初 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!

提交回复
热议问题