androidandroid-radiobutton

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>


Solution

  • Finally, i found answer by myself

    I just create custom layout and add to ListAdapter object

    radiobuttonlayout.xml

    <?xml version="1.0" encoding="utf-8"?>
    <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/checkedTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:checkMark="@drawable/radiobutton_drawable"
    android:gravity="center_vertical"
    android:text="New CheckedTextView"
    android:padding="@dimen/dp10"
    android:textColor="@color/white" />
    

    Java file code

    ListAdapter listAdapter = new ArrayAdapter<String>    (context,R.layout.radiobuttonlayout,aryStrLockscreens);
        listview_lockscreen.setAdapter(listAdapter);
    

    It's worked for me.