安卓:CheckBox的设置颜色颜色、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...

我已经搜查了许多地方似乎没有能够找出复选框绘制的复选框的边框。任何人都可以点我在正确的方向?

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

阅读全文

相关推荐

最新文章