Use image in RadioButton instead of text

check image

check text

In Android, I want to use RadioButton, but I do not want to check plain text. How to get the image on the first image instead of the second image? Using RadioGroupand RadioButton.

+4
source share
2 answers

Nothing special ... just add the following pictures to it:

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

For this effect:

enter image description here

RadioButtonIt contains by itself TextView, so you can perform all the operations that are present for anyone TextView.

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

+9
 <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>

, : -).

+3

Source: https://habr.com/ru/post/1584704/


All Articles