本文介绍了如何改变Android中的复选框勾号颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发android应用程序在那里,我使用复选框,但默认复选框tick颜色是蓝色的,所以我想把颜色更改为黄色。
解决方案
不幸的是,改变checkob的颜色不是勾选标记
<$> p $ p>
<?xml version =1.0encoding =utf-8?>
< selector xmlns:android =http://schemas.android.com/apk/res/android>
< item android:state_checked =trueandroid:drawable =@ drawable / checked/>
< item android:state_checked =falseandroid:drawable =@ drawable / unchecked/>
< / selector>
在您的布局文件中将此文件应用到您的复选框
< CheckBox
android:id =@ + id / cb
android:text =My CheckBox
android:button =@ drawable / cb_selector
android:layout_width =wrap_content
android:layout_height =wrap_content/>
在drawables文件夹中添加unchecked.png和checked.png。这些是复选框的检查和未选中图片。
I am developing android application In that i use check box but default check box tick color is blue so i want to change that color to yellow. is there any inbuilt property to set color to check box tick.
解决方案
Unfortunately, changing the color of checkob check mark isn't a simple attribute
Create a selector xml file in res\drawables\ folder with name cb_selector.xml
<?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/checked" />
<item android:state_checked="false" android:drawable="@drawable/unchecked" />
</selector>
In your layout file apply this file to your checkBox
<CheckBox
android:id="@+id/cb"
android:text="My CheckBox"
android:button="@drawable/cb_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Add a unchecked.png, and checked.png in your drawables folder. These are checked and unchecked image of checkbox.
这篇关于如何改变Android中的复选框勾号颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!