drawable folder > checkbox_checkbox1.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Unchecked -->
    <item android:state_checked="false">
        <shape>
            <stroke android:color="#c4cbd2" android:width="1dp" />
            <corners android:radius="4dp" />
            <solid android:color="#fff" />
        </shape>
    </item>
    <!-- Checked -->
    <item android:state_checked="true">
        <layer-list>
            <!-- 배경 -->
            <item>
                <shape>
                    <corners android:radius="4dp" />
                    <solid android:color="#e14f50" />
                </shape>
            </item>
            <!-- 이미지 영역 -->
            <item android:drawable="@drawable/checkbox_bg" android:top="4dp" android:right="4dp" android:bottom="4dp" android:left="4dp" />
        </layer-list>
    </item>
</selector>
 
cs

drawable folder > 체크이미지(checkbox_bg.png) 추가



background 속성에 사용

1
2
3
4
5
6
7
8
    <!-- 체크박스 -->
    <CheckBox
        android:checked="true"
        android:button="@android:color/transparent"
        android:background="@drawable/checkbox_checkbox1"
        android:layout_width="30dp"
        android:layout_height="30dp" />
    <!-- //체크박스 -->
cs

button 속성(attribute)을 투명(transparent)하게 해야한다



결과

Checked


Unchecked


+ Recent posts