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

新手上路,请多包涵

有什么方法可以在 android XML 中将复选框(勾选框)颜色更改为白色。 (我需要包含黑色勾号的白色勾选框,作为我在真实设备中的 android studio 中获得的预览)

这是我的复选框代码

<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" />

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

设计预览

在此处输入图像描述

真机

在此处输入图像描述

是否有类似 android:buttonTint 的属性,我可以使用它来实现真实设备中的更改。

原文由 Nadeesha Thilakarathne 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 658
2 个回答

colorAccent 设置为您想要的颜色:

 <style name="AppTheme" parent="Theme.AppCompat">
    <item name="colorAccent">#fff</item>
</style>

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

 <style name="WhiteCheck">
    <item name="colorAccent">#fff</item>
</style>


 <CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:theme="@style/WhiteCheck"/>

原文由 tachyonflux 发布,翻译遵循 CC BY-SA 3.0 许可协议

这是 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" />

原文由 Dragan Stojanov 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题