Skip to content Skip to sidebar Skip to footer

Remove Default Radio Button Checkbox When Using A Custom Selector

I am attempting to style a radio button and so I created a selector. Everything works except the standard radio button image still shows up. How do I remove the default radio but

Solution 1:

Set the button value to null in layout XML

android:button="@null"

Solution 2:

I found that I cannot remove the default radiobutton checkbox in the selector. I found that it can be removed by assigning the "button" property to null, in either the style or the definition of the radiobutton itself.

Here is an example using a style.

<RadioButtonandroid:id="@+id/myRadioButton"style="@style/RadioButtonStyle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/custom_radio_button"/><stylename="RadioButtonStyle"parent="@android:style/Widget.CompoundButton"><itemname="android:background">@drawable/radiobutton_selector</item><itemname="android:button">@null</item></style>

radiobutton_selector defines a selector that draws the button in its different checked states. Here is the checked state:

<itemandroid:state_checked="true"><shape><gradientandroid:startColor="@color/titleButtonCheckedGradientLight"android:centerColor="@color/titleButtonCheckedGradientDark"android:endColor="@color/titleButtonCheckedGradientDark"android:angle="270" /><strokeandroid:width="1dp"android:color="@color/titleButtonBorder" /><cornersandroid:radius="5dp" /></shape></item>

Solution 3:

If you wanna set custom background to RadioButton programmatically, then you can set it like this,

radioButton.setButtonDrawable(null);
radioButton.setBackgroundResource(R.drawable.your_custom_drawable);

Post a Comment for "Remove Default Radio Button Checkbox When Using A Custom Selector"