RadioButton改变圆圈颜色、CheckBox改变框的颜色

RadioButton:
第一种:
在style文件里面:

<style name="MyRadioButton" parent="Theme.AppCompat.Light">
        <item name="colorControlNormal">@color/colorPrimary</item>
        <item name="colorControlActivated">@color/colorAccent</item>
    </style>

xml布局:记住一定是theme,不能用style,style根本改变不了颜色

<RadioGroup
        android:id="@+id/rg_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <RadioButton
            android:id="@+id/rb_one"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="女"
            android:theme="@style/MyRadioButton"
            />

        <RadioButton
            android:id="@+id/rb_two"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="男"
            android:theme="@style/MyRadioButton" />

        <RadioButton
            android:id="@+id/rb_three"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="男"
            android:theme="@style/MyRadioButton" />

        <RadioButton
            android:id="@+id/rb_four"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="男"
            android:theme="@style/MyRadioButton" />
    </RadioGroup>

第二种:仅适用于api level 21或更高版本

<RadioButton
            android:id="@+id/rb_one"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="女"
            android:buttonTint="@color/your_color"
            />

values–>colors

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

第三种:
图片选择,未测试

CheckBox:

 <CheckBox
            android:id="@+id/cb_three"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="男"
            android:theme="@style/MyCheckBox"
            android:textColor="@color/view_title_text"/>

在style文件里面:

<style name="MyCheckBox" parent="Theme.AppCompat.Light">
        <item name="colorControlNormal">@color/grey</item>
        <item name="colorControlActivated">@color/mediumturquoise</item>
    </style>
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值