Checkbox 이미지 활용하기

안드로이드/android 2013. 5. 8. 15:02

체크박스를 예쁘게 또는 기능 적으로 이미지의 힘을 빌려야 할떄가 있다

특히 3.0 이하에서는 더욱더 그렇다


얼릉 4.0 이하는 사라져야 하는데...


// layout

<CheckBox android:id="@+id/cchkbox" android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:layout_alignParentLeft="true" android:layout_marginLeft="3dp"

        android:padding="10dp"

        android:focusable="false" android:clickable="false" android:button="@drawable/checkbox_sel" />



// drawable/checkbox_sel.xml


<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="false" android:drawable="@drawable/checkbox_dis" />

    <item android:state_checked="true" android:drawable="@drawable/checkbox_ena" />

    <item android:drawable="@drawable/checkbox_dis" />

</selector>



// JAVA

CheckBox ivChk = (CheckBox) findViewById(R.id.cchkbox);


ivChk.setChecked(true);     // @drawable/checkbox_ena 이 녀석이 활성화 될거임(체크된 상태)

ivChk.setChecked(false);   // @drawable/checkbox_dis 이 녀석이 활성화 될거임(체크되지 않은 상태)