drawable 폴더 > radiobutton_radiobutton01.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
27
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- UNSELECTED -->
    <item android:state_checked="false">
        <shape>
            <stroke android:color="#c4cbd2" android:width="1dp" />
            <corners android:radius="15dp" />
            <solid android:color="#fff" />
        </shape>
    </item>
    <!-- SELECTED -->
    <item android:state_checked="true">
        <layer-list>
            <!-- 배경 -->
            <item>
                <shape>
                    <corners android:radius="15dp" />
                    <solid android:color="#e14f50" />
                </shape>
            </item>
            <!-- 이미지 영역 -->
            <item android:drawable="@drawable/radio_bg" android:top="4dp" android:right="4dp" android:bottom="4dp" android:left="4dp" />
        </layer-list>
    </item>
</selector>
 
 
cs



background 속성에 사용

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    <!-- 라디오버튼 -->
    <RadioGroup
        android:checkedButton="@+id/btnRadio1"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <RadioButton
            android:id="@id/btnRadio1"
            android:layout_marginBottom="5dp"
            android:button="@android:color/transparent"
            android:background="@drawable/radiobutton_radiobutton1"
            android:layout_width="30dp"
            android:layout_height="30dp" />
        <RadioButton
            android:button="@android:color/transparent"
            android:background="@drawable/radiobutton_radiobutton1"
            android:layout_width="30dp"
            android:layout_height="30dp" />
    </RadioGroup>
    <!-- //라디오버튼 -->
cs
<RadioGroup> 속성 android:checkedButton="@+id/btnRadio1" 속성을 이용하여 디폴트(default) 체크를 한다.



결과



+ Recent posts