How to disable all click events of a layout?

后端 未结 7 1756
不知归路
不知归路 2020-12-16 10:51

I have a layout that contains many views. Is there an easy way to disable all its views click events?

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 11:36

    If you dont want to set all child views to disable state (because they may look different to enable state) you can use this approach:

    private fun toogleTouchable(canTouch: Boolean) {
            container.descendantFocusability =
                    if (value) {
                        container.requestFocus()
                        ViewGroup.FOCUS_BLOCK_DESCENDANTS
                    } else {
                        ViewGroup.FOCUS_AFTER_DESCENDANTS
                    }
        }
    

提交回复
热议问题