14

In my app, I want to get survey answers from the user. So, I've decided put smiley images to act as a radio buttons. Is it possible on android?

For example, I will show smiley images when user touches the image and it will be activated like a radio button. At a time, they will be allowed to only choose one. If anyone could guide me, I would appreciate it.

Example :Like this

Thanks in advance!

cdomination
  • 605
  • 1
  • 7
  • 25
hikoo
  • 517
  • 4
  • 10
  • 20
  • 2
    This may help you: http://stackoverflow.com/questions/11853245/making-radiogroup-radio-buttons-with-images-in-android-how – adalpari Jul 08 '16 at 12:20

5 Answers5

10

This question has been answered before Below is from @Benito-Bertoli

RadioButton - how to use a custom drawable?

Give your radiobutton a custom style:

<style name="MyRadioButtonStyle" parent="@android:style/Widget.CompoundButton.RadioButton">
    <item name="android:button">@drawable/custom_btn_radio</item>
</style>

custom_btn_radio.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_checked="true" android:state_window_focused="false"
      android:drawable="@drawable/btn_radio_on" />
   <item android:state_checked="false" android:state_window_focused="false"
      android:drawable="@drawable/btn_radio_off" />

   <item android:state_checked="true" android:state_pressed="true"
      android:drawable="@drawable/btn_radio_on_pressed" />
   <item android:state_checked="false" android:state_pressed="true"
      android:drawable="@drawable/btn_radio_off_pressed" />

   <item android:state_checked="true" android:state_focused="true"
      android:drawable="@drawable/btn_radio_on_selected" />
   <item android:state_checked="false" android:state_focused="true"
      android:drawable="@drawable/btn_radio_off_selected" />

   <item android:state_checked="false" android:drawable="@drawable/btn_radio_off" />
   <item android:state_checked="true" android:drawable="@drawable/btn_radio_on" />
</selector>

Replace the drawables with your own.

Community
  • 1
  • 1
BR89
  • 716
  • 1
  • 6
  • 23
8

Try like this

  <RadioGroup
    android:layout_width="wrap_content"
    android:orientation="horizontal"
    android:layout_height="wrap_content">

    <RadioButton
        android:button="@null"
        android:background="@mipmap/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <RadioButton
        android:button="@null"
        android:background="@mipmap/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <RadioButton
        android:button="@null"
        android:background="@mipmap/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RadioGroup>

output:(margin and pading by yourself)

enter image description here

Cgx
  • 753
  • 3
  • 6
3

I might be a bit late. Use android:button"@btmImage link"

<RadioButton
                    android:id="@+id/radio0"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:button="@drawable/ic_launcher"
                    android:text="male"
                    android:textColor="#90999d" />
ENOENT
  • 41
  • 5
3

Actually you just need to handle these two states, and it will work already.

<RadioButton
   android:id="@+id/paragraphRadioButton"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:button="@drawable/btn_paragraph"
   android:padding="14dp" />

btn_paragraph.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_paragraph_selected" android:state_checked="true" />
    <item android:drawable="@drawable/ic_paragraph" android:state_checked="false" />
</selector>
Morgan Koh
  • 2,297
  • 24
  • 24
2

I think these 3rd party libraries will help you achieve this functionality.

  1. SimpleRatingBar

  2. SmileBar

They are pretty easy to use also.

Rohan Sood
  • 178
  • 1
  • 14