Material Button Toggle Group single selection

前端 未结 4 2005
抹茶落季
抹茶落季 2021-02-19 04:55

How can I force a MaterialButtonToggleGroup to act like a RadioGroup as in having at least one selected item always? Setting setSingleSelection(true)

4条回答
  •  囚心锁ツ
    2021-02-19 05:38

    If you really want to do this, you can go about it this way in Kotlin.

    toggle_group.forEach { button ->
          button.setOnClickListener { (button as MaterialButton).isChecked = true }
    }
    

    This will prevent second click unchecking.

提交回复
热议问题