ListView 涟漪效应中的 RadioButton

问题描述

我有 RadioButton 涟漪效应问题。我想要得到这个:I have ripple in full background of list item

但我这个:I have ripple only around mark

我该如何实施?

解决方法

在 itemView 上应用单击侦听器,并在该侦听器中检查单选按钮为 对或错。将 backgroundTint 更改为单选按钮所需的颜色。

,

波纹效果可用于 API 级别 21+,您可以将其应用于单选按钮 android:background="?android:attr/selectableItemBackground" 用于每个单独的按钮

<RadioGroup
    android:id="@+id/radiogroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="?android:attr/selectableItemBackground"
        android:text="Option number one" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="?android:attr/selectableItemBackground"
        android:text="Option number two" />
</RadioGroup>
,

在带有 CheckedTextView 参数的 ListView 中使用 SINGLE_CHOICE_MODE