![](/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.