Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide radio button icon but not text

Tags:

I need to hide a radio button's icon: something like setting it to invisible, but only the icon, not the text (setInvisible hides also the text). The icon should still take up space, so that the text is aligned with that of the other radio buttons. Also, the radio button (its text) should be clickable.

In other words, what I want is for the icon to be "transparent" (not visible), but otherwise "be there": be clickable, take up space.

I need to do this programmatically, not in XML.

Any ideas?

like image 493
Luis Mendo Avatar asked Aug 28 '13 18:08

Luis Mendo


People also ask

How do I make radio buttons with text?

To label a radio button, add a <label> element after the <input> element and insert a for attribute with the same value as the id of the associated <input> element. Then, write your label text in the <label> tag.

What can I use instead of a radio button?

The alternatives to radio buttons are checkboxes and drop down boxes.


1 Answers

XML:

<RadioButton    android:paddingLeft="31dp"    android:button="@android:color/transparent" /> 

Java:

RadioButton myButton = (RadioButton) findViewById(R.id.radio);    myButton.setButtonDrawable(android.R.color.transparent);    myButton.setPadding(31, 0, 0, 0); 

setPadding() takes int values that represent Padding in Pixels, see Definition@Google so adjust the Padding as required.

like image 96
M.Bennett Avatar answered Oct 14 '22 22:10

M.Bennett