如何更改开关样式

时间:2016-09-17 09:51:33

标签: android android-layout android-fragments android-linearlayout

我正在尝试更改Switch的样式,当我向布局添加ThumbTrack属性时,它会从布局中隐藏Switch。如果我从布局中删除ThumbTrack,则会显示自定义切换。请指导我如何更改Switch样式。

   <Switch
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:id="@+id/switchNotifications"
        android:layout_centerHorizontal="true"
        android:paddingTop="150dp"
        android:text="@string/notification_settings"
        android:textColor="@color/white"
        android:checked="true"
        android:track="@drawable/track"
        android:thumb="@drawable/thumb"

        />

Thumb.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:drawable="@drawable/gray_track" />
    <item android:state_pressed="true"  android:drawable="@drawable/color_thumb" />
    <item android:state_checked="true"  android:drawable="@drawable/color_thumb" />
    <item                               android:drawable="@drawable/gray_track" />
</selector>

Track.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="false"  android:drawable="@drawable/color_thumb" />
    <item                               android:drawable="@drawable/gray_track" />
</selector>

ColorThumb

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <size android:height="40dp"  />
    <gradient android:height="40dp" android:startColor="@color/tabAccessoryButtonSelected" android:endColor="@color/tabAccessoryButtonSelected"/>
</shape>

GrayTrack

<size android:height="40dp"  />
<gradient android:height="40dp" android:startColor="@color/tabAccessoryButtonSelected" android:endColor="@color/tabAccessoryButtonSelected"/>

0 个答案:

没有答案