chrisTina
chrisTina

Reputation: 2378

Using image in RadioButton instead of text

check image

check text

In Android, I want to use RadioButton, but I do not want to check a plain text. How can I get the display in the first image instead of the second image? Using RadioGroup and RadioButton.

Upvotes: 4

Views: 5852

Answers (2)

Ankit Bansal
Ankit Bansal

Reputation: 1811

Nothing special to do.. just add drawable in it like this:

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_launcher"/>

For an effect like this:

enter image description here

RadioButton itself contains a TextView as default.. so you can do all the operations those are present for any TextView.

BONUS: If you want to change the circular dot that shows check status, just update the android:button tag to refer your own drawable.

Upvotes: 10

mcd
mcd

Reputation: 1432

 <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/radio1"
            />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            />
    </RadioGroup>

this is the alteranative approch which i am using :-).

Upvotes: 3

Related Questions