HK.avdalyan
HK.avdalyan

Reputation: 734

Can not create Custom Radio Button

I try to create custom radio button but the result is not good, with this code: custom_radio.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/radio_on" android:state_checked="true"/>
    <item android:drawable="@drawable/radio_on" android:state_pressed="true"/>
    <item android:drawable="@drawable/radio_off"/>

</selector>

and main.xml

<RadioGroup
                    android:id="@+id/radioSex"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="25dp"
                    android:orientation="vertical" >

                    <RadioButton
                        android:id="@+id/male"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:checked="true"
                        android:text="@string/male"
                        android:background="@xml/custom_radio"
                        android:textColor="@color/white" />

                    <RadioButton
                        android:id="@+id/female"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/female"
                        android:background="@xml/custom_radio"
                        android:textColor="@color/white" />
                </RadioGroup>

the result is this: enter image description here

How to solve this ?

Upvotes: 0

Views: 141

Answers (1)

Blackbelt
Blackbelt

Reputation: 157437

add

 android:button="@null"

to your RadioButton. Also drawable like xml should be placed inside the drawable folder

Upvotes: 1

Related Questions