【发布时间】:2014-07-08 00:35:06
【问题描述】:
我有两个单选按钮,看起来像普通按钮。我想通过使用带有选择器的 radio_button.xml 来更改它们的背景颜色。 如果我使用小 .png 图像来设置背景,那么它工作正常。 但我尝试了类似的代码只使用颜色(整数),但它不起作用。我做错了什么?
带背景图片的代码:
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:text="LEFT"
android:id="@+id/radioLeft"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="@drawable/radio_button"
android:checked="true" />
<RadioButton
android:text="RIGHT"
android:id="@+id/radioRight"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="@drawable/radio_button" />
</RadioGroup>
radio_button.xml
<?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/gray_dot" />
<item android:state_checked="false"
android:drawable="@drawable/blue_dot" />
</selector>
button_colors.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<color name="button_black">#000000</color>
<color name="button_white">#ffffff</color>
<color name="button_blue">#00afdb</color>
<color name="button_gray">#dcdcdc</color>
</resources>
我尝试替换
android:drawable="@drawable/blue_dot"
与
android:background="@color/button_blue"
但它不起作用。如何解决?
【问题讨论】:
标签: button xamarin selector radio