Change Switch state without animation

前端 未结 7 1946
醉酒成梦
醉酒成梦 2020-12-09 07:54

In my Android project, I have a ListView with rows containing SwitchCompat items (AppCompat for Switch widget).

My problem occ

7条回答
  •  佛祖请我去吃肉
    2020-12-09 08:18

    For Kotlin developer:

    fun SwitchCompat.setCheckedWithoutAnimation(checked: Boolean) {
        val beforeVisibility = visibility
        visibility = View.INVISIBLE
        isChecked = checked
        visibility = beforeVisibility
    }
    

    And the usage:

    mySwitch.setCheckedWithoutAnimation(true)
    

提交回复
热议问题