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


drawable 폴더 > button_button01.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
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 
    <item>
        <layer-list>
            <!-- shadow (밑으로) : 그림자 -->
            <item android:top="3dp">
                <shape>
                    <corners android:radius="3dp" />
                    <solid android:color="#1f000000" />
                </shape>
            </item>
            <!-- background (위로) -->
            <item android:bottom="3dp">
                <shape>
                    <corners android:radius="3dp" /
                    <solid android:color="#00854a" />
                    <stroke android:width="1dp" android:color="#6a6a6a" />
                </shape>
            </item>
        </layer-list>
    </item>
</selector>
 
cs

버튼을 커스텀 한다

<layer-list>태그 밑에 <item>태그 2개를 넣어서 하나는 버튼의 배경과 테두리를 다른하나는 그림자를 만든다



커스텀하고자 하는 버튼의 background 속성에 사용

1
2
3
4
5
6
7
8
9
10
    <!-- 버튼 -->
    <Button
        android:text="버튼"
        android:textColor="#fff"
        android:textSize="16dp"
        android:background="@drawable/button_button1"
        android:layout_gravity="center_vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <!-- //버튼 -->
cs





결과




+ Recent posts