Reputation: 1
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="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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="http://schemas.android.com/apk/res/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="http://schemas.android.com/apk/res/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="http://schemas.android.com/apk/res/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="http://schemas.android.com/apk/res/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?
i tried to find solution about customizing switchcompat widget but, there was not design with shorter width and longer height
Upvotes: 0
Views: 17