How to remove RadioButton circle in Android 4.4.4

I made a special RadioButton button that looks like this on an Android 5.0 device.

enter image description here

These RadioButtons are created dynamically, as shown in the following methods. Thus, the first redioButtonPresenterApparence method sets its appearance by removing the circle (by setting buttonDrwable to null. The second method sets the background of the buttons later.

private void radioButtonPresenterApparence(RadioButton presenter, int icon) { Drawable drawable = getResources().getDrawable(icon); presenter.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); presenter.setButtonDrawable(null); presenter.setGravity(Gravity.CENTER); } private void updateButtonsBackground(){ int childCount = getChildCount(); BackgroundSelector bgSelector = new BackgroundSelector(childCount); for(int i = 0; i < childCount; i++){ View rb = getChildAt(i); rb.setBackgroundResource( bgSelector.getBackgroundResource(i) ); rb.requestLayout(); } requestLayout(); } 

My problem is that when testing on Samsung Android 4.4.4 devices (not sure about other manufacturers) it looks like this.

enter image description here

PS: This is the code created by RadioButton. You can check this in the following way:

 private void addPresenter(int icon){ RadioButton presenter = new RadioButton(getContext()); //Create new RadioButton radioButtonPresenterApparence(presenter, icon); //Set icon and configure aparence addView(presenter); //Add new button to Selector presenterParentAparance(presenter); //Config button inside parent requestLayout(); //Request layout update to Selector } 
+7
source share
3 answers

Find your switches in layout.xml and give them the following:

 android:button="@null" 

This should do the same as presenter.setButtonDrawable(null); Except that it really works

Edit:

In the case of a button created by code, use:

 presenter.setButtonDrawable(new StateListDrawable()); 

Actually helps as it is equivalent

 android:button="@null" 
+9
source

Based on Marijjan's answer, I created a WrappedRadioButton class that overrides the setButtonDrawable methods:

 class WrappedRadioButton : RadioButton { constructor(context: Context) : super(context) constructor(context: Context, attrs: AttributeSet) : super(context, attrs) constructor( context: Context, attrs: AttributeSet, defStyleAttr: Int ) : super(context, attrs, defStyleAttr) @RequiresApi(api = 21) constructor( context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int ) : super(context, attrs, defStyleAttr, defStyleRes) override fun setButtonDrawable(resId: Int) { super.setButtonDrawable(StateListDrawable()) } override fun setButtonDrawable(drawable: Drawable?) { super.setButtonDrawable(StateListDrawable()) } } 

So when I want to use RadioButton with android:button="@null" , I just use WrappedRadioButton instead. There is no need to call setButtonDrawable manually.

0
source

setting a custom drawing mode for radiobutton is based on the principle of star forward, you can write something like this programmatically,

 radioButton.setButtonDrawable(null); radioButton.setBackgroundResource(R.drawable.your_custom_drawable); 
-1
source

All Articles