1

I'm trying to put a letter inside my custom Radio Button. They already have 'yes' and 'no' and 'skip' below them and I want to also add a 'v', an 'x' and a '-' to them. I want those letters to be inside the custom Radio Button.

I've got this Radio Button:

<RadioButton
    android:id="@+id/radioButtonNeutral"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:button="@android:color/transparent"
    android:drawableTop="@drawable/ic_choice_neutral"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:onClick="onRadioButtonClicked"
    android:visibility="visible"/>

Which uses this drawable:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!--big light circle-->
    <item
        android:bottom="1dp"
        android:left="1dp"
        android:right="1dp"
        android:top="1dp">
        <shape android:shape="oval">
            <solid android:color="#EEEEEE" />

            <size
                android:width="33dp"
                android:height="33dp" />

            <stroke
                android:width="1dp"
                android:color="#404040" />
        </shape>
    </item>
    <!--small dark circle-->
    <item
        android:bottom="7dp"
        android:left="7dp"
        android:right="7dp"
        android:top="7dp">
        <shape android:shape="oval">
            <solid android:color="#AEAEAE" />

            <stroke
                android:width="1dp"
                android:color="#464646" />
        </shape>
    </item>
</layer-list>

I can't use android:text because i've already used it to put 'yes', 'no' and 'skip' below the button. (using .setText() in the activity) The RadioButton is inside a RelativeLayout, so I could put a TextView over(on top of) the RadioButton, but I think that is more of a workaround than a solution. I tried putting a TextView inside the RadioButton tag, but that wasn't allowed.

How do I show text (a letter) inside my custom radio button?

Janneman96
  • 374
  • 1
  • 8
  • 24
  • u wii have to use images. –  Jul 30 '16 at 12:02
  • 1
    There is no easy way of doing this. You will either have to do something hacky with overlaying the text above it, or something complicated like drawing a custom object. Either way, it would be easier to create your own implementation of the mechanism, for example, to put buttons instead of radiobuttons, and then regulate their behaviour, or something along those lines... – Aleksandar Stefanović Jul 30 '16 at 12:09
  • I ended up using Button instead. I added this code http://stackoverflow.com/questions/9318331/keep-android-button-selected-state to keep it selected and I disabled all buttons when one is pressed, as it moves me to the next screen. – Janneman96 Jul 30 '16 at 13:46

2 Answers2

0

Have you considered checking this thread? Adding custom radio buttons in android. As Viren says in the comments, you will have to refer to a custom image.

Community
  • 1
  • 1
  • I used http://stackoverflow.com/questions/12432553/radiobutton-how-to-use-a-custom-drawable and http://stackoverflow.com/questions/21178193/android-draw-circle-with-text-inside and http://stackoverflow.com/questions/21613308/how-to-draw-a-circle-inside-a-circle-using-android-xml-shapes to write what i've got so far. But I guess i should make it a custom Button instead of a RadioButton, i've got the single selection algorithem lying around anyways. – Janneman96 Jul 30 '16 at 12:17
0

use drawbles having those words on it. edit in paint or anything else

Ganesh Karewad
  • 1,158
  • 12
  • 21
  • As you can see, i've used an xml drawable, I prefer that over an image and I wonder if it is possible to put a letter in that drawable. – Janneman96 Jul 30 '16 at 12:50