我制作了一个自定义RadioButton,在Android 5.0设备中的外观如下。

android - 如何在Android 4.4.4中删除单选按钮圈-LMLPHP

这些RadioButton是动态创建的,如以下方法所示。因此,第一种方法redioButtonPresenterApparence设置其外观移除圆圈(将buttonDrwable设置为null。第二种方法稍后设置按钮背景。

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();
}

我的问题是在Samsung Android 4.4.4设备(对其他制造商不确定)上进行相同测试时,显示如下。

android - 如何在Android 4.4.4中删除单选按钮圈-LMLPHP

PS:这是代码创建的RadioButton。您可以按照以下方法进行检查:
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
}

最佳答案

在layout.xml中找到您的单选按钮,并为其指定以下内容:

android:button="@null"

这应该和presenter.setButtonDrawable(null);做同样的事情
除了这确实有效

编辑:

如果使用代码创建按钮,请使用:
presenter.setButtonDrawable(new StateListDrawable());

实际上有帮助,因为它等效于
android:button="@null"

关于android - 如何在Android 4.4.4中删除单选按钮圈,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37882492/

10-10 23:31
查看更多