How to disable all click events of a layout?

后端 未结 7 1767
不知归路
不知归路 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:23

    Here is a Kotlin extension function implementation of Parag Chauhan's answer

    fun View.setAllEnabled(enabled: Boolean) {
        isEnabled = enabled
        if (this is ViewGroup) children.forEach { child -> child.setAllEnabled(enabled) }
    }
    

提交回复
热议问题