先看看定義好的樣子:


xml程式碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="me.jason_996.ftpuploadpicwithprogress.MainActivity">
    

    <RadioButton
        android:id="@+id/radioBtn01"
        style="@style/RadioButtonStyles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="測試測試-1"
        android:textColor="#F86B50"
        android:textSize="18sp" />

    <RadioButton
        android:id="@+id/radioBtn02"
        style="@style/RadioButtonStyles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="測試測試-2"
        android:textColor="#F86B50"
        android:textSize="18sp" />

    <RadioButton
        android:id="@+id/radioBtn03"
        style="@style/RadioButtonStyles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="測試測試-3"
        android:textColor="#F86B50"
        android:textSize="18sp" />
</LinearLayout>

style樣式:
<resources>
    <!-- RadioButtonStyles start -->
    <style name="RadioButtonStyles">
        <item name="android:button">@drawable/selector_radio_bg</item>
    </style>
    <!-- RadioButtonStyles start -->

</resources>

selector選擇器:

<?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/ic_xuan"/>
    <!-- not selected -->
    <item android:state_checked="false" android:drawable="@drawable/ic_noxuan"/>
</selector>

ic_xuan/ic_noxuan是圖片