Android CheckBox modify the water ripple effect when the selected color and remove the check

Foreword

All know that the native Android controls eye color is hot, so the actual development, there will be changes, and check boxes are commonly used in the actual development, such as the protocol agreed to check on.

The first to write a control

<CheckBox
        android:text="同意服务协议"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

running result

Here Insert Picture Description

This is the native controls, does this color look good?
So to change, at res folder values add the following code in the file styles.xml:

	<!--复选框样式,未勾选时为灰色,勾选好为黄色-->
    <style name="MyCheckBox" parent="Theme.AppCompat.Light">
        <item name="colorControlNormal">#ADB6AF</item>
        <item name="colorControlActivated">#F7F13D</item>
    </style>

And then apply the style in the layout file:

	<CheckBox
        android:text="同意服务协议"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:theme="@style/MyCheckBox"/>

running result:
Here Insert Picture Description

This modification is different from the way to switch the background by, I kept this control check and uncheck animation effects, only modify the color before and after selected in this way is better, android: theme = "@ style / MyCheckBox ", MyCheckBox is the name of the style I have just defined.
Removing water ripple effect when in fact one line of code to get selected, that is, the background is transparent to, @ android: color / transparent

Modify the layout file:

	<CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:text="同意服务协议"
        android:theme="@style/MyCheckBox" />

Then you run up on it.

Published 51 original articles · won praise 17 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_38436214/article/details/105192967