Android 单击时更改单选按钮的颜色

Android 单击时更改单选按钮的颜色,android,android-radiogroup,android-radiobutton,Android,Android Radiogroup,Android Radiobutton,我有一个放射组有3个单选按钮。默认情况下,当我单击单选按钮时,它会变成蓝色。我需要更改颜色,比如说,当我单击第一个颜色时,它应该变成黄色,第二个颜色变成蓝色,第三个颜色变成绿色 我看过一些通过设置单选按钮样式进行自定义的教程,如,但它隐藏了所有按钮 这是我的XML <RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="

我有一个
放射组
有3个
单选按钮
。默认情况下,当我单击单选按钮时,它会变成蓝色。我需要更改颜色,比如说,当我单击第一个颜色时,它应该变成黄色,第二个颜色变成蓝色,第三个颜色变成绿色

我看过一些通过设置单选按钮样式进行自定义的教程,如,但它隐藏了所有按钮

这是我的XML

<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/studentImage"
    android:layout_alignParentRight="true"
    android:layout_alignRight="@+id/studentImage"
    android:layout_alignTop="@+id/studentImage"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/rb1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible" />

    <RadioButton
        android:id="@+id/rb2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible" />

    <RadioButton
        android:id="@+id/rb3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible" />
</RadioGroup>

您可以使用可绘制的状态列表,如下所述:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/color_pressed" /> <!-- pressed -->
<item android:drawable="@drawable/default_button" /> <!-- default -->
</selector> 


按颜色和deafult按钮将是每个按钮状态的可绘图项,每个单选按钮可以有多个选择器

您可以尝试使用不同的选择器来选择所有单选按钮。检查此链接@PerlDeveloper,Thnx该链接对我有效。@Aleena我正在寻找相同的信息。你能就如何实现这一目标提出建议吗?PearlDeveloper似乎删除了您认为有用的注释…当我将此样式应用于我的单选按钮时,如
android:button=“@drawable/radio”
,它会隐藏按钮。