问题描述
我搜索了很多地方,但似乎无法找出复选框边框的 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_blue 和 cbunchk_blue
Here I am uploading my own images which I used in place of cbchk_blue and cbunchk_blue
这篇关于Android:设置复选框的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!