更改单选按钮的圆圈颜色

Amandeep Singh |

我想在我的项目之一中更改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>

结果:

彩色的Android单选按钮

如果您想通过代码(也是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
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章