Sreyas
Sreyas

Reputation: 784

Android Custom radio button not getting displayed

Hi I have created a custom radio button checked and unchecked using xml drawable and I made a selector as well. When I set the button attribute as my custom made selector, In emulator it is showing correctly. But when I run this project in a real device nothing is getting displayed.I can see only the text . My real device is Android 4.4.2.

unselected.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- larger circle at the back -->
<item
    android:width="@dimen/radiooutter"
    android:height="@dimen/radiooutter"
    android:gravity="center">
    <shape
        android:shape="oval"
        android:useLevel="false">
        >

        <solid android:color="@android:color/transparent" />

        <!-- thicker outer boarder -->
        <stroke
            android:width="2dp"
            android:color="@color/colorPrimary"/>
    </shape>
</item>


<!-- inner circle -->
<item
    android:width="@dimen/inner"
    android:height="@dimen/inner"
    android:gravity="center">
    <shape
        android:shape="oval">
        <solid android:color="@android:color/transparent" />

    </shape>
</item>

selected.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- larger circle at the back -->
 <item
    android:width="@dimen/radiooutter"
    android:height="@dimen/radiooutter"
    android:gravity="center">
    <shape
        android:shape="oval">

        <solid
            android:color="#FFFFFF"/>

        <!-- thicker outer boarder -->
        <stroke
            android:width="1dp"
            android:color="@color/colorPrimary"/>
    </shape>
</item>


<!-- inner circle -->
<item
    android:width="@dimen/inner"
    android:height="@dimen/inner"
    android:gravity="center">
    <shape
        android:shape="oval">
        <solid
            android:color="@color/colorPrimaryLight"/>

    </shape>
</item>

selector.xml

 <selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_checked="true"     android:drawable="@drawable/radioselected"/>
<item android:state_checked="false" android:drawable="@drawable/radiounselected"/>
</selector>

radiobutton in layout xml

android:id="@+id/opt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/selector"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="First option"
android:textSize="16dp"/>

Upvotes: 2

Views: 1048

Answers (1)

Sathish Kumar J
Sathish Kumar J

Reputation: 4335

Try this

 android:id="@+id/opt"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@drawable/selector"
 android:button="@android:color/transparent"
 android:paddingLeft="10dp"
 android:paddingRight="10dp"
 android:text="First option"
 android:textSize="16dp"/>

this will helps you

Upvotes: 1

Related Questions