问题描述
如何更改了Android复选框的默认颜色从绿色对号蓝色为特定的复选框?
How do I change the default color of the Android checkbox from green checkmarks to blue for a particular CheckBox?
推荐答案
不幸的是,改变颜色不是一个简单的属性。该选中标记的图像,所以你必须创建一个自定义图像。看看这个example
Unfortunately, changing the colour isn't a simple attribute. The checkmark is an image, so you have to create a custom image. Take a look at this example
创建一个选择器的XML文件是这样:
Create a selector xml file such as this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/star_down" />
<item android:state_checked="false" android:drawable="@drawable/star" />
</selector>
保存此XML文件中的水库\可绘\
文件夹。然后,你的布局文件中把它应用到你的复选框是这样的:
save this xml file in your res\drawables\
folder. Then inside your layout file apply it to your checkBox like this:
<CheckBox
android:text="Custom CheckBox"
android:button="@drawable/checkbox_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
在这个例子中你命名你选择XML文件checkbox_selector.xml,你会需要一个star_down.png,并star.png您可绘制文件夹中。您可以使用此技术通过改变系统复选框图像任何你想要的颜色和引用改变的PNG文件中选择创建不同颜色的复选框。
In this example you'd name your selector xml file "checkbox_selector.xml" and you'd need a star_down.png, and star.png in your drawables folder as well. You can use this technique to create different colored checkboxes by altering the system checkbox images to whatever color you want and referencing the altered png files in a selector.
这篇关于Android的CheckBox的更改默认颜色复选标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!