如何在android XML中将复选框(复选框)颜色更改为白色

Nad*_*hne 17 xml android

有没有办法在Android XML中将复选框(勾选框)颜色更改为白色.(我需要包含黑色勾号的白色勾选框,作为我在真实设备中的android工作室中获得的预览)

这是我的复选框代码

<CheckBox
    android:textSize="15sp"
    android:textColor="#fff"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Save Loging "
    android:id="@+id/checkBox"
    android:layout_below="@id/PasswordeditText"
    android:checked="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:buttonTint="#fff" />
Run Code Online (Sandbox Code Playgroud)

当我添加android:buttonTint="#fff"预览时显示我需要的更改,但它在真实设备中不起作用

设计预览

在此输入图像描述

真实设备

在此输入图像描述

是否有任何属性android:buttonTint可以用来实现真实设备中的更改.

tac*_*lux 52

设置colorAccent为您想要的颜色:

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="colorAccent">#fff</item>
</style>
Run Code Online (Sandbox Code Playgroud)

或者,如果您不想更改主题,请创建一个新主题并仅将其应用于复选框:

<style name="WhiteCheck">
    <item name="colorAccent">#fff</item>
</style>
Run Code Online (Sandbox Code Playgroud)
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:theme="@style/WhiteCheck"/>
Run Code Online (Sandbox Code Playgroud)


Dra*_*nov 10

这是tachyonflux答案的变化:

尝试更改buttonTint:

<style name="my_checkbox_style">
    <item name="buttonTint">#fff</item>
</style>

<CheckBox
            android:id="@+id/my_checkbox"
            style="@style/my_checkbox_style"
            android:background="#000" />
Run Code Online (Sandbox Code Playgroud)


shw*_*iya 6

我们可以通过在 xml 中使用此属性轻松更改复选框颜色

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/COLOR_WHICH_YOU_WANT" />
Run Code Online (Sandbox Code Playgroud)


Aha*_*kat 5

来自 XML

<androidx.appcompat.widget.AppCompatCheckBox
    android:id="@+id/cbCheck"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:buttonTint="@android:color/white" />
Run Code Online (Sandbox Code Playgroud)

或来自 Java/Kotlin:

CompoundButtonCompat.setButtonTintList(cbCheck, ColorStateList.valueOf(Color.WHITE));
Run Code Online (Sandbox Code Playgroud)