Android.widget.RadioButton
lastmod 2026-11-10created 2016-06-113 edits
RadioButton은 안드로이드에서 여러 선택지 가운데 하나만 고를 수 있는 라디오 버튼 위젯 클래스이다. CompoundButton을 상속해 체크 상태를 갖지만 한 번 선택한 뒤에는 사용자가 직접 해제할 수 없고, 보통 RadioGroup 안에 여러 개를 넣어 그룹 안에서 하나만 선택되도록 묶는다. 레이아웃 XML 에서 android:button 속성에 상태별 drawable 셀렉터를 지정하면 버튼 모양을 바꿀 수 있다.
XML example
Drawable selecter XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_radio_2" android:state_checked="true"/>
<item android:drawable="@drawable/icon_radio_1" android:state_checked="false"/>
</selector>
Layout XML:
<RadioGroup
android:id="@+id/createaccount_popup__user_info__login_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/createaccount_popup__user_info__login_man"
style="@style/createaccount_popup__checkbox_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/general__48rhythm__4dp"
android:button="@drawable/icon_radio_selector"
android:checked="true"
android:gravity="center_vertical"
android:text="@string/createaccount_popup__user_info__login_man" />
<RadioButton
android:id="@+id/createaccount_popup__user_info__login_woman"
style="@style/createaccount_popup__checkbox_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/icon_radio_selector"
android:checked="false"
android:gravity="center_vertical"
android:text="@string/createaccount_popup__user_info__login_woman" />
</RadioGroup>