[英]Change icons of checked and unchecked for Checkbox for Android
Instead of having a check mark for the icon, I want a custom star (I have checked and unchecked icons). 我没有图标的复选标记,而是想要一个自定义星(我已选中和取消选中图标)。 Can this be done through a property?
这可以通过财产来完成吗? Or must I declare a custom widget that derives from Checkbox?
或者我必须声明一个派生自Checkbox的自定义小部件吗?
Kind of a mix: 混合类型:
Set it in your layout file :- 在布局文件中设置它: -
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new checkbox"
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox" />
where the @drawable/checkbox will look like: @ 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"
让它工作
I realize this is an old question, and the OP is talking about using custom gx that aren't necessary 'checkbox'-looking, but there is a fantastic resource for generating custom colored assets here: http://kobroor.pl/ 我意识到这是一个老问题,OP正在谈论使用不需要'复选框'看的自定义gx,但是这里有一个生成自定义彩色资产的绝佳资源: http : //kobroor.pl/
Just give it the relevant details and it spits out graphics, complete with xml resources, that you can just drop right in. 只需给它相关的细节,它就会吐出图形,完整的xml资源,你可以直接进入。
One alternative would be to use a drawable/textview instead of a checkbox and manipulate it accordingly. 一种替代方法是使用drawable / textview而不是复选框并相应地操作它。 I have used this method to have my own checked and unchecked images for a task application.
我已经使用此方法为任务应用程序提供了自己的已检查和未检查的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.