有什么方法可以将选择芯片设置为默认选项吗?另外,如果只选中了一个芯片,就无法取消选中任何芯片?
最佳答案
您可以在 ChipGroup
中使用这些属性组件:
app:singleSelection="true"
。通过这种方式,ChipGroup
可以配置为一次只允许检查一个芯片,使用app:checkedChip
定义默认选择
类似于:
<com.google.android.material.chip.ChipGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:singleSelection="true"
app:checkedChip="@id/ch2">
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ch1"
android:text="M"/>
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ch2"
android:text="F"/>
</com.google.android.material.chip.ChipGroup>
关于Android:设置默认选择芯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57464556/