Android:设置复选框的颜色 [英] Android: Set color of CheckBox

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

问题描述

我搜索了很多地方,但似乎无法找出复选框边框的 CheckBox 可绘制对象.谁能指出我正确的方向?

I've searched a number of places and don't seem to be able to figure out the CheckBox drawable for the border of the check box. Can anyone point me in the correct direction?

这是未选中的样子(几乎看不到框)

Here is what it looks like unchecked (Can barely see the box)

这里是选中状态

这就是我想让它看起来的样子.

Here is what I'm trying to make it look like.

推荐答案

您可以为此使用自定义复选框 xml 文件.将下面的xml代码保存在drawables文件夹中,命名为custom_checkbox.xml:

You can use a custom check box xml file for this. Save the below xml code in drawables folder, name it custom_checkbox.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/cbchk_blue"
        android:state_focused="false">
    </item>
    <item android:state_checked="true" 
        android:drawable="@drawable/cbchk_blue"
        android:state_focused="true">
    </item>
    <item android:state_checked="false" 
        android:drawable="@drawable/cbunchk_blue"
        android:state_focused="false">
    </item>
    <item android:state_checked="false" 
        android:drawable="@drawable/cbunchk_blue"
        android:state_focused="true">
    </item>
</selector>

然后将此文件用作复选框的背景,如下所示:

Then use this file as background of your checkbox like this:

       <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/custom_checkbox"
        android:id="@+id/checkBox" />

这里我上传了我自己的图片,我用它来代替 cbchk_bluecbunchk_blue

Here I am uploading my own images which I used in place of cbchk_blue and cbunchk_blue

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

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