如何在android中更改复选框刻度线颜色 [英] How to change check box tick color in android

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

问题描述

我正在开发 android 应用程序,因为我使用复选框,但默认复选框刻度颜色是蓝色,所以我想将该颜色更改为黄色.是否有任何内置属性可以将颜色设置为复选框勾选.

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 checkbox check mark isn't a simple attribute

resdrawables 文件夹中创建一个选择器 xml 文件,名称为 cb_selector.xml

Create a selector xml file in resdrawables 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"/>

在您的 drawables 文件夹中添加 unchecked.pngchecked.png.这些是复选框的选中和未选中的图像.

Add a unchecked.png, and checked.png in your drawables folder. These are checked and unchecked image of checkbox.

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

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