android – 更改单选按钮的圆形颜色
作者:互联网
我想改变RadioButton的圆圈颜色,我无法理解要设置的属性.我所拥有的背景颜色是黑色,因此它变得不可见.我想将圆圈的颜色设置为白色.
解决方法:
更简单,只需设置buttonTint颜色:(仅适用于api级别21或以上)
<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中,你的颜色在这种情况下是偏红的:
<color name="your_color">#e75748</color>
结果:
如果你想通过代码(也是api 21及以上)来做到这一点:
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
}
标签:android,android-radiobutton 来源: https://codeday.me/bug/20190915/1806389.html