【发布时间】:2014-05-05 22:59:18
【问题描述】:
按下时如何在android中创建这种类型的checkbox。我试过了 。我可以知道实现目标的正确方法是什么吗?也许这个问题太简单了,但我没有找到任何合适的解决方案。请帮帮我。
我想创建这样的
当它未选中时,它看起来像:
这是我的checkbox 的 XML 代码:
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:button="@drawable/custom_checkbox"/>
这里是 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/checked" />
<item android:state_pressed="true"
android:drawable="@drawable/checked" />
<item android:drawable="@drawable/unchecked" />
</selector>
这里是checked.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#54d66A" android:endColor="#54d66A" android:angle="270"/>
<stroke android:width="4px" android:color="#ffc0c0c0" />
<size android:height="20dp" android:width="20dp"/>
</shape>
这是我的输出:
【问题讨论】:
-
为什么不用图片?
-
为了我的学习目的先生。
-
使用另一个drawable作为背景。
-
是你不知道外绿环怎么弄的问题?