安卓:CheckBox的设置颜色 [英] Android: Set color of CheckBox

查看:130
本文介绍了安卓: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 code。在可绘制文件夹,命名为 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_blue cbunchk_blue

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

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