본문 바로가기

CheckBox(체크박스) 이미지 변경하기

반응형

체크박스의 이미지 변경 ( selector 이용)


xml 파일을 새로 만들어준다. ( 본 포스팅에서는 checkbox.xml로 xml파일을 만들어줌 )

생성해준 xml파일은 drawable 폴더에다 해주었다.
< ?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/Checked가 false일 때, 이미지 파일" />
    <item android:state_checked="true" android:drawable="@drawable/Checked가 true일 때, 이미지 파일" />
    <item android:drawable="@drawable/기본 이미지, 보통 false 일 때의 이미지를 사용한다." />
< /selector>
그리고 체크박스를 사용할 xml / layout에 CheckBox 생성
<CheckBox
               android:id="@+id/checkBox"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:textSize="16sp"
               android:checked="true"
               android:text="체크박스"
               android:button="@null"
               android:background="@android:color/transparent"
               android:drawableLeft="@drawable/checkbox" />
이부분이 중요하다. 만들어준 셀렉터 파일명을 적어준다.
android:drawableLeft="@drawable/checkbox"

반응형

댓글


Copyright ⓒ SmartWeb All rights reserved.