Search code examples
androidandroid-radiogroupandroid-radiobutton

Customizing radiobuttons in android


I am extending a question i asked few time back in stackoverflow - Here


As seen in the answer - Here I get my required output

I get a output as:

enter image description here


What i am trying to do::

Keeping all other functionality i want to show an image in place of Button text


How can i achieve this !


Solution

  • You could not set the text AND set android:button="@drawable/some_drawable" instead of android:button="@android:color/transparent", as in:

    <RadioButton
        android:id="@+id/radio0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/yourbuttonbackground"
        android:button="@drawable/some_drawable"
        android:checked="true"
    />
    

    You have only 3 ways to set drawables in a RadioButton:

    • background (you need this for the "border layer-list")
    • button (recommended)
    • compound drawable/s (less recommended, since the positions are fixed at the sides, but you might want to experiment)