android中checkbox自定義樣式


1、首先res/drawable中定義編寫如下樣式: 

<?xml version="1.0" encoding="utf-8"?>  
<selector  xmlns:android="http://schemas.android.com/apk/res/android">  
    <item android:drawable="@drawable/check_true" android:state_checked="true"></item>  
    <item android:drawable="@drawable/check_true" android:state_selected="true"></item>  
    <item android:drawable="@drawable/check_true" android:state_pressed="true"></item>  
    <item android:drawable="@drawable/check_false"></item>  
</selector>  

2、在layout中添加checkbox控件: 

<CheckBox  
            android:id="@+id/radioButton1"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:background="@drawable/btn_check"  
            android:button="@null"  
            android:checked="true"/>  

其中drwable/btn_check為1中頂一個文件名稱,另外必須將android:button設置為@null。 
@drawable/check_true和@drawable/check_false為checkbox不同狀態的圖片,可自行設計。 


免責聲明!

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



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