2011-06-15 8 views
2

나는 안드로이드 응용 프로그램을 가지고 있습니다. 7 개의 체크 박스가 필요한 작업이 있지만 SDK에서 제공하는 기본 확인란의 크기가 매우 커서 많은 공간이 필요하므로 사용자 정의 된 확인란을 개발하려고했습니다.안드로이드에서 사용자 정의 확인란 만들기

두 개의 이미지 (선택 및 선택 취소)를 캡처했습니다. 한 번의 클릭으로 토글합니다. 즉, 선택을 클릭하면 선택되지 않은 것으로 변환되고 그 반대의 경우도 마찬가지입니다.

는하지만이 작업을 수행하려면 다른 방법이 알고 싶어 ..

답변

6

그것은 당신의 체크 박스에 적합한 그릴 수 xml 파일을 배치하여 약간의 간단한있어 사용자가 설정해야 할 이미지를 대응하는 상태. = 버튼을 그릴 수/체크 박스 "

<CheckBox android:id="@+id/chkFav" android:layout_width="wrap_content" 
     android:layout_marginRight="0dp" android:button="@drawable/checkbox" 
       android:layout_height="wrap_content" android:clickable="true"/> 
@ 드로어 블 이름 checkbox.xml

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

및 코드 이상으로 설정하여 체크 박스에 아래의 코드는 안드로이드 사용하여 조작 할 수

장소

관련 문제