如何更改复选框的颜色? [英] How to change the color of a CheckBox?

查看:51
本文介绍了如何更改复选框的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改 Android 中默认的 CheckBox 颜色?
默认情况下,CheckBox 颜色为绿色,我想更改此颜色.
如果不可能,请告诉我如何制作自定义 CheckBox?

How do I change the default CheckBox color in Android?
By default the CheckBox color is green, and I want to change this color.
If it is not possible please tell me how to make a custom CheckBox?

推荐答案

如果你的 minSdkVersion 是 21+ 使用 android:buttonTint 属性来更新复选框的颜色:

If your minSdkVersion is 21+ use android:buttonTint attribute to update the color of a checkbox:

<CheckBox
  ...
  android:buttonTint="@color/tint_color" />

在使用 AppCompat 库并支持 21 以下 Android 版本的项目中,您可以使用 buttonTint 属性的兼容版本:

In projects that use AppCompat library and support Android versions below 21 you can use a compat version of the buttonTint attribute:

<CheckBox
  ...
  app:buttonTint="@color/tint_color" />

在这种情况下,如果您想对 CheckBox 进行子类化,请不要忘记改用 AppCompatCheckBox.

In this case if you want to subclass a CheckBox don't forget to use AppCompatCheckBox instead.

以前的答案:

您可以使用 android:button="@drawable/your_check_drawable" 属性更改 CheckBox 的可绘制对象.

You can change CheckBoxs drawable using android:button="@drawable/your_check_drawable" attribute.

这篇关于如何更改复选框的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆