21

Is it possible to make Radio Buttons in Android, where there are image representation to a button instead of a regular buttons? I want it to look something like that:

enter image description here

The cyan in the middle represents the selected button.

How can I do it?

Igal
  • 5,833
  • 20
  • 74
  • 132

1 Answers1

30

The RadioButton class has a buttonDrawable member, derived from CompoundButton.

There are multiple ways you can change this drawable.

From java:

myRadioButton.setButtonDrawable(resourceId or Drawable);

From xml:

<RadioButton
    android:button="@drawable/yourdrawable" 
    ...
/>

If you just want the checked/unchecked state look differently, then

  • Add a new selector xml by rightclicking your res folder -> New -> Android xml -> select Drawable in the upper dropdown -> choose selector (in eclipse)
  • To setup this selector, please take a look at this link
  • From now on you can set your freshly created selector to any of your checkboxes/radiobuttons by using its id.
Balázs Édes
  • 13,452
  • 6
  • 54
  • 89