標籤:
原文網址:http://forum.maiziedu.com/thread-515-1-1.html
heckbox組件是一種可同時選中多項的基礎控制項,即複選框,在android學習中,Checkbox是一款非常重要的UI組件,由於它的展現形式美觀性和協調性不符合我們的需求,我們需要自訂這個組件,方法很簡單,只需要增加修改xml檔案即可。
首先需要準備兩張圖片,一張是選中的圖片,一張是未選中的圖片。
android開發設定選擇框
在drawable下建立檔案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>
- <item android:state_checked="false" android:drawable="@drawable/unchecked"></item>
- <item android:drawable="@drawable/unchecked"></item><!-- The default one -->
- </selector>
複製代碼
android開發應用自訂
設定button屬性值為上面定義的custom_checkbox。
- <CheckBox
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:button="@drawable/custom_checkbox"
- />
複製代碼
以上就實現了Checkbox組件自訂,有興趣的網友可以運行看看結果。
【轉】Android學習基礎自訂Checkbox組件