How to disable all click events of a layout?

后端 未结 7 1752
不知归路
不知归路 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
                    }
        }
    
    0 讨论(0)
提交回复
热议问题