【问题标题】:Material Chip the selection behavior doesn't work材料芯片选择行为不起作用
【发布时间】:2022-01-02 17:24:07
【问题描述】:

我无法理解芯片的工作原理。我想做一个包含要选择的动态过滤器的视图。选择芯片时,有按下效果(OK),但是芯片没有停留在选中状态...

我在 XML 中做了这个简单的例子。结果是一样的……

<com.google.android.material.chip.ChipGroup
        android:id="@+id/tags"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/Widget.MaterialComponents.Chip.Choice"
        android:layout_marginTop="@dimen/keyline_0"
        app:chipSpacingHorizontal="8dp"
        app:lineSpacing="8dp">

        <com.google.android.material.chip.Chip
            android:id="@+id/chip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test"/>

        <com.google.android.material.chip.Chip
            android:id="@+id/chip2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test2"/>

        <com.google.android.material.chip.Chip
            android:id="@+id/chip3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test3"/>

        <com.google.android.material.chip.Chip
            android:id="@+id/chip4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test4"/>

    </com.google.android.material.chip.ChipGroup>

【问题讨论】:

  • 请查看此链接filter chip,您需要更改您的芯片的style

标签: android android-chips


【解决方案1】:

要设置芯片视图的样式,您需要将@style/Widget.MaterialComponents.Chip.Choice 样式应用于Chip 元素。 (不适用于ChipGroup)。

看看https://material.io/components/chips/android#choice-chip

【讨论】:

    【解决方案2】:

    这样做

        chips.isCheckable = true
    

    然后设置这个

        chips.setOnCheckedChangeListener { compoundButton, b ->
                  
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      相关资源
      最近更新 更多