我有下面的芯片组,当我点击已经检查过的芯片时,它未被选中,但是我必须始终拥有一个检查过的芯片。行为类似于无线电组。
<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>
您可以要求具有该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-alpha02
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句