I am using radioButton
in my app but by default my radioButton
color is black and when I select it that turns to color accent color that I have mentioned in my color.xml
but I want to change radioButton
initial color and selected color to white color. How I am able to do so. I tried background color but it changes background color property. Please help.
Asked
Active
Viewed 621 times
0

Abhishek kumar
- 4,347
- 8
- 29
- 44

Deepanshi Gupta
- 127
- 1
- 1
- 7
-
by default selected color gets from style and that is colorAscent.. try new style and add it to your radio button – Bapusaheb Shinde Sep 04 '17 at 04:42
-
4Possible duplicate of [Change color of a radio button](https://stackoverflow.com/questions/18696275/change-color-of-a-radio-button) – Vishal Thakkar Sep 04 '17 at 04:44
-
@VishalThakkar that is not providing any answer – Deepanshi Gupta Sep 04 '17 at 04:51
-
have you try that answers solution? – Vishal Thakkar Sep 04 '17 at 04:52
-
`is not providing any answer` it **is providing** 9 answers, can't you see? – Vladyslav Matviienko Sep 04 '17 at 04:59
1 Answers
1
First Put this code in 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>
Now make rb_drawable.xml in drawable folder
<?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>
Now make 2 more files for radio button check/uncheck in drawable folder
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>
Finally change style of radio button in layout xml
<RadioButton
android:layout_width="wrap_content"
style="@style/radionbutton"
android:checked="false"
android:layout_height="wrap_content"
/>

Lokesh Desai
- 2,607
- 16
- 28