更改单选按钮的圆圈颜色 [英] Change the circle color of radio button
本文介绍了更改单选按钮的圆圈颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想改变的圆圈颜色我的一个项目中的 RadioButton,但我不知道要设置哪个属性.背景颜色为黑色,因此不可见.我想将圆圈的颜色设置为白色.
I want to change the color of the circle of RadioButton in one of my projects, but I could not understand which property to set. The background color is black, so it gets invisible. I want to set the color of the circle to white.
推荐答案
设置 buttonTint 颜色更简单(仅适用于 API 级别 21 或更高级别):
It is simpler just setting 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 file, 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屋!
查看全文