我有下面这个芯片组,当我点击一个已经检查过的芯片时,它会被取消检查,但是我必须始终有一个已检查的芯片。其行为类似于无线电组。
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:checkedChip="@id/chip_1"
app:singleSelection="true">
<com.google.android.material.chip.Chip
android:id="@+id/chip_1"
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chip1"
app:chipBackgroundColor="@color/chip_color" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_2"
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chip2"
app:chipBackgroundColor="@color/chip_color" />
</com.google.android.material.chip.ChipGroup>发布于 2019-11-20 07:39:29
您可以要求一个具有app:selectionRequired属性的选定芯片。
类似于:
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:checkedChip="@id/chip_1"
app:selectionRequired="true"
app:singleSelection="true">请注意:app:checkedChip或初始选择并不是必需的。如果没有设置,则在没有选择的情况下,它可以工作。
注意:这需要最低版本的1.2.0。
https://stackoverflow.com/questions/58245202
复制相似问题