admin管理员组

文章数量:1288075

i want to make Switch width shorter and height longer. But it isn't work. Below is my xml code.

// layout_custom_switch
<LinearLayout xmlns:android=";
    xmlns:app=";
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <androidx.appcompat.widget.SwitchCompat
        android:id="@+id/widget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:thumb="@drawable/shape_switch_thumb"
        app:track="@drawable/selector_switch"/>
</LinearLayout>

// shape_switch_thumb
<shape xmlns:android=";
    android:shape="oval">
    <size android:width="16dp" android:height="16dp"/>
    <solid android:color="#FFFFFF"/>
    <stroke android:width="8dp" android:color="#00FFFFFF"/>
</shape>

// selector_switch
<selector xmlns:android=";>
    <item android:drawable="@drawable/bg_switch_track_on" android:state_checked="true"/>
    <item android:drawable="@drawable/bg_switch_track_off" android:state_checked="false"/>
</selector>

// bg_switch_track_on
<shape xmlns:android=";
    android:shape="rectangle">
    <corners android:radius="30dp"/>
    <size android:width="16dp" android:height="24dp" />
    <solid android:color="#927448"/>
</shape>

// bg_switch_track_off
<shape xmlns:android=";
    android:shape="rectangle">
    <corners android:radius="30dp"/>
    <size android:width="16dp" android:height="24dp" />
    <solid android:color="#BBAB94"/>
</shape>

when i change the bg_switch_track_on(off) android:height = "24dp" thumb's width and height is same (16dp) but, looks oval. how can i make width shorter and height longer?

enter image description here

i tried to find solution about customizing switchcompat widget but, there was not design with shorter width and longer height

本文标签: androidCustomizing SwitchCompatStack Overflow