如何仅更改开关按钮轨道宽度?

时间:2016-02-01 07:11:26

标签: android android-button

我有一个像enter image description here

这样的切换按钮

我的代码

<style name="CustomSwitch">
    <item name="android:switchMinWidth">0dp</item>
    <item name="android:track">@drawable/switch_track</item>
    <item name="android:thumb">@drawable/switch_thumb</item>
    <item name="android:textOff">NO</item>
    <item name="android:textOn">YES</item>
</style>

切换曲目

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle"
    android:useLevel="false"
    android:visible="true">
    <solid android:color="@color/colorTransparentGrey"></solid>
    <corners android:radius="@dimen/switch_thumb_radius" />
    <size android:height="@dimen/switch_track_height" />
</shape>

切换拇指

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false">
        <shape android:shape="rectangle">
            <size android:width="@dimen/switch_track_width" />
            <corners android:radius="@dimen/switch_thumb_radius" />
            <solid android:color="@color/colorAccent" />
            <stroke android:color="@color/colorTransparent" android:width="@dimen/switch_thumb_padding"></stroke>
        </shape>
    </item>
    <item android:state_checked="true">
        <shape android:shape="rectangle">
            <size android:width="@dimen/switch_track_width" />
            <corners android:radius="@dimen/switch_thumb_radius" />
            <solid android:color="@color/colorPrimary" />
            <stroke android:color="@color/colorTransparent" android:width="@dimen/switch_thumb_padding"></stroke>
        </shape>
    </item>
</selector>

Witch工作正常,但我需要减小音轨宽度以使切换像enter image description here一样,我怎么可能只改变音​​轨宽度?

0 个答案:

没有答案