16

Is there a way to style a RadioButton as a flat button? I have four options:

| btn1 | btn2 | btn3 | btn4 |

instead of having the little radio circle next to each, I'd like to show each as just a plain flat button. Is that possible without having to draw them myself?

Thanks

user246114
  • 50,223
  • 42
  • 112
  • 149

4 Answers4

26

Yes it is possible.

In xml set, android:button="@null"

And in case you want to do it dynamically, setButtonDrawable(new StateListDrawable());

Ashraf Bashir
  • 9,686
  • 15
  • 57
  • 82
Raeesaa
  • 3,267
  • 2
  • 22
  • 44
4

Yes, you can change the drawable used for a radio button.

android:button (or setButtonDrawable) controls the image used for the circle. Set it to null if you want no image.

You could then set the background of the radio button with android:background or setBackgroundResource to a normal button-style background.

Joseph Earl
  • 23,351
  • 11
  • 76
  • 89
0

Try this segmented control button library on github: https://github.com/bookwormat/segcontrol

Intrications
  • 16,782
  • 9
  • 50
  • 50
0

Please see my question here for related help. I have been trying to get the "radio circle" to disappear too (which i can get it to work in the xml as shown in my example on the linked page) but it doesn't work if i try to do it dynamically.

Hope this helps and any help on my issue would be appreciated. Thanks.

Community
  • 1
  • 1
aveyD
  • 525
  • 6
  • 12
  • 1
    Actually setting the button drawable to android's empty resource worked... All i had to do was: myRadioButton.setButtonDrawable(android.R.id.empty); myRadioButton.setPadding(5,0,5,0); and then it worked (except for some weird inconsistencies with the Xoom... ie: The Xoom gets a "android.content.res.Resources$NotFoundException: File from drawable resource Id #_______" when trying to use the "android.R.id.empty" resource) – aveyD Apr 28 '11 at 22:26
  • fixed this problem. See here: http://stackoverflow.com/questions/5997359/android-r-id-empty-broken-in-xoom-honeycomb – aveyD May 19 '11 at 17:14