Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove RadioButton circle in Android 4.4.4

I made a custom RadioButton that looks as follow in a Android 5.0 device.

enter image description here

These RadioButtons are dynamic created as shown in the follow methods. So the first method redioButtonPresenterApparence sets its appearance removing circle (setting buttonDrwable to null. The second method set the buttons background 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 when testing the same on Samsung Android 4.4.4 devices (not sure about other manufactories), it shows as follow.

enter image description here

PS: It's a code created RadioButton. You can check it in the follow method:

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
}
like image 850
wviana Avatar asked Jun 17 '16 13:06

wviana


People also ask

How do I turn off RadioButton in android?

Android RadioButton has only two states: checked or unchecked. Apart from these, the radio button can't have any other value. You can't uncheck a checked RadioButton. The only way to uncheck is to select some other RadioButton belonging to that RadioGroup.

Can you uncheck radio button android?

RadioButton is a two states button which is either checked or unchecked. If a single radio button is unchecked, we can click it to make checked radio button. Once a radio button is checked, it cannot be marked as unchecked by user.

How do you check whether a RadioButton is checked or not in android?

You can check the current state of a radio button programmatically by using isChecked() method. This method returns a Boolean value either true or false. if it is checked then returns true otherwise returns false. Below is an example code with explanation in which we checked the current state of a radio button.


1 Answers

Find your radio buttons in layout.xml and give them this:

android:button="@null"

This should do the same thing as presenter.setButtonDrawable(null); Except that this actually works

Edit:

In case of code created button, please use:

presenter.setButtonDrawable(new StateListDrawable());

Actually helps as it is an equivalent of

android:button="@null"
like image 118
Marijan Avatar answered Oct 05 '22 22:10

Marijan