Android 使用两种状态自定义开关按钮

Android 使用两种状态自定义开关按钮,android,android-button,android-styles,android-switch,Android,Android Button,Android Styles,Android Switch,我想让我的开关具有如下所示的两种状态 custom_thumb.xml <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/ic_nights_stay" android:state_checked="false"> </item> <item andr

我想让我的开关具有如下所示的两种状态


custom_thumb.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_nights_stay"

        android:state_checked="false">

    </item>
    <item android:drawable="@drawable/ic_wb_sunny"
        android:state_checked="true">

    </item>
</selector>

custom_track.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false">
        <shape android:shape="rectangle">
            <corners android:radius="100dp" />
            <solid android:color="#ffffff" />
            <stroke android:width="1dp" android:color="#8c8c8c" />
            <size android:width="40dp" android:height="40dp" />
        </shape>
    </item>

    <item android:state_checked="true">
        <shape android:shape="rectangle">
            <corners android:radius="100dp" />
            <solid android:color="#fff" />
            <stroke android:width="1dp" android:color="#8c8c8c" />
            <size android:height="40dp"
                android:width="40dp"
                />
        </shape>
    </item>
</selector>


上面的代码隐藏了一个非活动状态。您知道如何在switch中同时显示这两个视图吗。

android:thumb是switch中的图标(类似于圆形图标)。在您的自定义中,拇指看起来像轨迹。所以拇指可以是图标,对吗?我的开关有两个状态,所以我想会有两个带图标的拇指?我做错什么了吗?安卓:拇指是开关中的图标(像圆圈图标)。在您的自定义中,拇指看起来像轨迹。所以拇指可以是图标,对吗?我的开关有两个状态,所以我想会有两个带图标的拇指?我做错什么了吗?
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false">
        <shape android:shape="rectangle">
            <corners android:radius="100dp" />
            <solid android:color="#ffffff" />
            <stroke android:width="1dp" android:color="#8c8c8c" />
            <size android:width="40dp" android:height="40dp" />
        </shape>
    </item>

    <item android:state_checked="true">
        <shape android:shape="rectangle">
            <corners android:radius="100dp" />
            <solid android:color="#fff" />
            <stroke android:width="1dp" android:color="#8c8c8c" />
            <size android:height="40dp"
                android:width="40dp"
                />
        </shape>
    </item>
</selector>