android checkbox樣式


 

1. 首先要導入你准備用作CheckBox選中和補選中狀態的兩圖片到res的drawable中,如checkbox_checked.png,checkbox_normal.png;

2. 在res/drawable中添加checkbox.xml,定義checkbox的state list drawable圖片 
[html]  view plain copy
 
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3.   
  4. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  5.   
  6.   
  7.     <item android:state_checked="true" android:drawable="@drawable/checkbox_checked" /> <!-- checked -->  
  8.   
  9.   
  10.     <item android:state_checked="false" android:drawable="@drawable/checkbox_normal" /> <!-- default -->  
  11.   
  12.   
  13. </selector>  

復制代碼

3. 在Layout中修改checkbox的屬性:android:button="@drawable/checkbox" 定制button樣式
[html]  view plain copy
 
  1. <CheckBox android:layout_height="wrap_content" android:id="@+id/chkItem" android:button="@drawable/checkbox"></CheckBox>  

這樣就完成了定制工作,效果如下:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM