更改单选按钮的圆圈颜色 [英] Change Circle color of radio button

查看:110
本文介绍了更改单选按钮的圆圈颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改在我的项目之一中的RadioButton ,我不知道要设置哪个属性.我的背景色是黑色,因此不可见.我想将圆圈的颜色设置为白色.

I want to change the color of the circle of RadioButton in one of my project, I could not understand which property to set. The background color I am having is black so it gets invisible. I want to set the color of the circle to white.

推荐答案

更简单,只需设置buttonTint颜色:(仅适用于21级或以上的api)

More simple, just set the buttonTint color: (only works on api level 21 or above)

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radio"
    android:checked="true"
    android:buttonTint="@color/your_color"/>

在您的values/colors.xml中,在这种情况下将您的颜色变成红色:

in your values/colors.xml put your color in this case a reddish one:

<color name="your_color">#e75748</color>

结果:

如果您想通过代码(也是api 21及更高版本)来做到这一点:

If you want to do it by code (also api 21 and above):

if(Build.VERSION.SDK_INT>=21)
{

    ColorStateList colorStateList = new ColorStateList(
            new int[][]{

                    new int[]{-android.R.attr.state_enabled}, //disabled
                    new int[]{android.R.attr.state_enabled} //enabled
            },
            new int[] {

                    Color.BLACK //disabled
                    ,Color.BLUE //enabled

            }
        );                       


    radio.setButtonTintList(colorStateList);//set the color tint list
    radio.invalidate(); //could not be necessary
}

这篇关于更改单选按钮的圆圈颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆