0
我在我的应用中使用radioButton
,但默认情况下,我的radioButton
颜色为黑色,当选择颜色为我在color.xml
中提及的颜色时,但我想要将radioButton
初始颜色和所选颜色更改为白色。我如何能够这样做。我尝试了背景颜色,但它改变了背景颜色属性。请帮忙。无法更改android中的单选按钮圆圈颜色
我在我的应用中使用radioButton
,但默认情况下,我的radioButton
颜色为黑色,当选择颜色为我在color.xml
中提及的颜色时,但我想要将radioButton
初始颜色和所选颜色更改为白色。我如何能够这样做。我尝试了背景颜色,但它改变了背景颜色属性。请帮忙。无法更改android中的单选按钮圆圈颜色
首先将这个代码style.xml
<!-- custom style -->
<style name="radionbutton"
parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:button">@drawable/rb_drawable</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
现在让rb_drawable.xml在绘制文件夹
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/radio_unchecked" android:state_checked="false" android:state_focused="true"/>
<item android:drawable="@drawable/radio_unchecked" android:state_checked="false" android:state_focused="false"/>
<item android:drawable="@drawable/radio_checked" android:state_checked="true" android:state_focused="true"/>
<item android:drawable="@drawable/radio_checked" android:state_checked="true" android:state_focused="false"/>
</selector>
现在做的单选按钮,检查2个文件/在绘制文件夹取消
radio_unchecked.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="1dp" android:color="@color/colorAccent"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
radio_checked.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:width="1dp" android:color="@color/colorAccent"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
</item>
<item android:top="5dp" android:bottom="5dp" android:left="5dp" android:right="5dp">
<shape android:shape="oval">
<solid android:width="1dp" android:color="@color/colorAccent"/>
<size android:width="10dp" android:height="10dp"/>
</shape>
</item>
</layer-list>
最后默认
<RadioButton
android:layout_width="wrap_content"
style="@style/radionbutton"
android:checked="false"
android:layout_height="wrap_content"
/>
改变单选按钮的风格布局XML选择颜色从风格得到,这是colorAscent ..尝试新的风格,并将其添加到您的单选按钮 –
[更改单选按钮的颜色]的可能的副本(https://stackoverflow.com/questions/18696275/change-color-of-a-radio-button) –
@VishalThakkar没有提供任何答案 –