체크박스의 이미지 변경 ( 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"
이부분이 중요하다. 만들어준 셀렉터 파일명을 적어준다.
'DEVELOPMENT > ANDROID' 카테고리의 다른 글
[android] C 서버와 소켓통신 (0) | 2015.02.16 |
---|---|
[android] 해상도 별 아이콘 크기 (0) | 2014.04.23 |
[android] SharedPreferences 사용하기 (0) | 2014.04.16 |
[android] Custom ListView (커스텀 리스트뷰) Footer를 이용한 더보기 구현 (0) | 2014.04.15 |
[android] Intent로 Web URL 연결 (0) | 2014.04.15 |