【发布时间】:2020-04-19 15:41:44
【问题描述】:
在最后的版本中,按钮切换组支持 singleSelection 和 selectionRequired
implementation 'com.google.android.material:material:1.2.0-alpha06'
app:selectionRequired="true"
app:singleSelection="true
效果很好,但是当我尝试获取已选择按钮的 id 时,返回 -1
var x = toggleGroup.checkedButtonId
如何始终检查按钮 ID? 我知道 -1 表示当前按钮已被选中。但我有几个 toggleGroup,我需要即时知道选择了哪些按钮 id。
【问题讨论】:
-
该方法getCheckedButtonId()在组不处于单选模式时返回-1。
-
我检查了我在 xml 中也有 app:singleSelection="true" 以及调试器和 isSingleSelection(),它们在代码运行中返回“true”。也许这个问题是因为我使用“视图绑定”
标签: android kotlin material-design