【发布时间】:2014-09-30 09:12:32
【问题描述】:
我有一个 RadioGroup 有 3 个 Radio Buttons。默认情况下,当我单击单选按钮时,它会变为蓝色。我需要改变颜色,比如说,当我点击第一个时,它应该变成Yellow,第二个Blue,第三个变成Green。
我看过一些通过设置单选按钮样式来自定义的教程,例如Is it possible to change the radio button icon in an android radio button group,但它隐藏了所有按钮。
这是我的 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>
【问题讨论】:
-
您可以尝试 this 为所有单选按钮使用不同的选择器。
-
@PerlDeveloper,感谢链接,它对我有用。
-
@Aleena 我也在寻找同样的信息。您能否就如何实现这一目标提出建议? PearlDeveloper 似乎已删除您认为有用的评论...
标签: android android-radiogroup android-radiobutton