Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize default theme of radio button in android?

i want to change default theme of radio button to custom but it's not changing the theme. please help me out

styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="android:radioButtonStyle">@style/radionbutton</item>
</style>

<!-- custom style -->
<style name="radionbutton"
     parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
    <item name="android:button">@drawable/radiobutton_drawable</item>
</style>

radiobutton_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="false" android:drawable="@mipmap/radio_unselected" >
</item>
<item android:state_checked="true" android:drawable="@mipmap/radio_selected">
</item>

like image 547
Dharmesh Dhameliya Avatar asked Dec 15 '22 08:12

Dharmesh Dhameliya


1 Answers

Declare custom style in your styles.xml file.

<style name="MyRadioButton" parent="Theme.AppCompat.Light">  
  <item name="colorControlNormal">@color/indigo</item>
  <item name="colorControlActivated">@color/pink</item>
</style>  

Apply this style to your RadioButton via android:theme attribute.

<RadioButton  
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="true"
    android:text="Radio Button"
    android:theme="@style/MyRadioButton"/>

only if your activity extends AppCompatActivity

like image 94
batsheva Avatar answered Mar 05 '23 09:03

batsheva