使用自定义选择器时删除默认的单选按钮复选框
问题描述:
我正在尝试设计一个单选按钮的样式,所以我创建了一个选择器。除了标准的单选按钮图像仍然显示以外,一切正常。我如何删除默认的单选按钮复选框。我试图将drawable分配给一个空字符串,但编译器不喜欢它。使用自定义选择器时删除默认的单选按钮复选框
这是我选择的国家之一的代码:
<item android:state_checked="true" android:drawable="">
<shape>
<gradient
android:startColor="#808080"
android:centerColor="#2F2F2F"
android:endColor="#2F2F2F"
android:angle="270" />
<stroke
android:width="2dp"
android:color="@color/black" />
<corners
android:radius="5dp" />
</shape>
</item>
答
我发现我不能删除默认单选按钮复选框中选择。我发现它可以通过将“button”属性分配给null,在样式或单选按钮本身的定义中删除。
以下是使用样式的示例。
<RadioButton
android:id="@+id/myRadioButton"
style="@style/RadioButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/custom_radio_button"/>
<style name="RadioButtonStyle" parent="@android:style/Widget.CompoundButton">
<item name="android:background">@drawable/radiobutton_selector</item>
<item name="android:button">@null</item>
</style>
radiobutton_selector限定绘制在其不同检查状态下的按钮的选择器。这里是选中状态:
<item android:state_checked="true">
<shape>
<gradient
android:startColor="@color/titleButtonCheckedGradientLight"
android:centerColor="@color/titleButtonCheckedGradientDark"
android:endColor="@color/titleButtonCheckedGradientDark"
android:angle="270" />
<stroke
android:width="1dp"
android:color="@color/titleButtonBorder" />
<corners
android:radius="5dp" />
</shape>
</item>
答
设置按钮值设置为null在布局XML
android:button="@null"
+3
感谢您的回答。我从我的问题中看到2012年2月15日的评论,我也发现了这一点。 – 2013-07-25 19:33:40
你为什么试图删除绘制一起?你可以用适合你需求的东西来替代它吗? – Flynn 2012-02-15 17:28:48
我想要一个单选按钮的功能,但希望它看起来像一个按钮。具体而言,我想有两个并排切换的按钮。其中一个按钮出现了,另一个出现了。有没有更好的解决方案比我要去的地方更好? – 2012-02-15 19:13:53
我居然发现我可以用下面的'android:button =“@ null”' – 2012-02-15 21:20:30