4

I want some ImageViews to work as RadioButtons. But I don't want the mini-button of a RadioButton to select it; I want this mini-button to disappear, and the ImageView to be the entire button. Thus, a solution like the following one is not good.

<RadioButton
    android:id="@+id/myId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableRight="@drawable/myIcon"/>

Is there a widget or something which I can use to use ImageViews as RadioButtons, or should I program myself all the logic of the buttons?

Santiago Gil
  • 1,292
  • 7
  • 21
  • 52

3 Answers3

3

I will suggest to create your custom radio button. check this answer of Evan Bashir

Community
  • 1
  • 1
KDeogharkar
  • 10,939
  • 7
  • 51
  • 95
2

you can try with button attribute like bellow.

<RadioButton
android:id="@+id/myId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/myIcon"/>

or through grammatically.

myRadioButton.setButtonDrawable(resourceId or Drawable);

and you can change the images while selecting the RB through the following xml file...save this file in drawable folder and call it in the button attribute or grammatically .

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/star_down" />
<item android:state_checked="false" android:drawable="@drawable/star" />
</selector>
brahmy adigopula
  • 617
  • 3
  • 15
1

Just set the image in the android:background of the RadioButton's XML declaration. Also set the android:button to transparent: android:button="@android:color/transparent"

If you want to have different states - create a selector with different images for the two states.

Seishin
  • 1,493
  • 1
  • 19
  • 30