簡體   English   中英

避免芯片組未經檢查

[英]Avoid Chip Group to get unchecked

我有這個下面的芯片組,當我點擊一個已經選中的芯片時,它會被取消選中,但我必須始終有一個選中的芯片。 該行為類似於無線電組。

<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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM