把CheckBox的方塊換成圖片或其他

先在drawable下創建一個selector 選中爲true 否則爲false

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

< /selector>

在style裏聲明

<style name="checkbox2" parent="@android:style/Widget.CompoundButton.CheckBox">
    <item name="android:button">@drawable/check_box_changed</item>
</style>

最後在佈局中用

<CheckBox
            android:id="@+id/car_check_all"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/checkbox2" />
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章