如何更改 Material 设计复选框中勾号的颜色?

How to change the color of the tick in a Material Design Checkbox?

<com.google.android.material.checkbox.MaterialCheckBox
android:theme="@style/CheckBoxTheme"
/>

这是复选框

这是style

<style name="CheckBoxTheme" parent="Theme.AppCompat.Light">
    <item name="colorControlNormal">#FFC107</item>
    <item name="colorControlActivated">#9C27B0</item>
</style>

我想在不改变文本+框的背景的情况下,在里面打一个蓝色的勾

我试过了

<com.google.android.material.checkbox.MaterialCheckBox
android:theme="@style/CheckBoxTheme"
android:background="@color/blue_banner_bg"
/>

然而我得到的是这个

我该怎么办?

您应该为 CheckBox 使用自定义图标。它应该是一个 selector 像这样的可绘制对象

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false"
          android:drawable="@drawable/button_normal" /> <!-- unchecked -->
    <item android:state_checked="true"
          android:drawable="@drawable/button_checked" /> <!-- checked -->
    <item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>

Drawables button_checkedbutton_normal 应该由您定义。

然后像这样使用这个drawable

<com.google.android.material.checkbox.MaterialCheckBox
    android:theme="@style/CheckBoxTheme"
    android:button="@drawable/checkbox_selector"
/>

更多信息here and here

希望对您有所帮助。