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
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:
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.