![](/img/trans.png)
[英]How to check if checkbox is checked or unchecked in android application?
[英]Change icons of checked and unchecked for Checkbox for Android
我没有图标的复选标记,而是想要一个自定义星(我已选中和取消选中图标)。 这可以通过财产来完成吗? 或者我必须声明一个派生自Checkbox的自定义小部件吗?
混合类型:
在布局文件中设置它: -
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new checkbox"
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox" />
@ drawable /复选框的外观如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/checkbox_on_background_focus_yellow" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/checkbox_off_background_focus_yellow" />
<item android:state_checked="false"
android:drawable="@drawable/checkbox_off_background" />
<item android:state_checked="true"
android:drawable="@drawable/checkbox_on_background" />
</selector>
这是android:button="@drawable/selector_checkbox"
让它工作
我意识到这是一个老问题,OP正在谈论使用不需要'复选框'看的自定义gx,但是这里有一个生成自定义彩色资产的绝佳资源: http : //kobroor.pl/
只需给它相关的细节,它就会吐出图形,完整的xml资源,你可以直接进入。
一种替代方法是使用drawable / textview而不是复选框并相应地操作它。 我已经使用此方法为任务应用程序提供了自己的已检查和未检查的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.