当前位置: 首页 > 面试题库 >

How to change Width of Android's Switch track?

俞子实
2023-03-14
问题内容

I’m going crazy with this tiny problem. I have a ‘switch’ Form widget, but no
matter how much I try, I cannot make it narrower. Even if I have one character
instead of ‘ON’ or ‘OFF’, the size of switch remains the same. The ‘thumb’
becomes small, but it has to be dragged over the same distance as before.
Changing the ‘layout_width’ to a smaller value simply cuts off the remaining
track. ‘minWidth’ doesnt seem to do anything.

Anybody knows how I can do this? Ideally I want just an empty thumb and I’ll
colour code both thumb to know which is which.

XML code:

<Switch
     android:id="@+id/switch3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Switch"
     android:textOff=" "
     android:textOn=" " />

I am gettin this: enter image descript<a href=ion here" src="https://imgs.xnip.cn/cj/l/14/4227ba96-d75f-48f6-bb2d-9416e60c582e.png" />

but I want something like this: enter image descript<a href=ion here" src="https://imgs.xnip.cn/cj/l/43/8626fd51-6241-4ac6-94b6-720ec72dc4c4.png" />


问题答案:

set your desired width of switch in this attribute.

android:switchMinWidth

like

<Switch
android:id="@+id/switchVisitAgain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="1dp"
android:checked="false"
android:gravity="center_vertical"
android:switchMinWidth="56dp"
android:textOff=""
android:textOn=""
android:thumb="@drawable/round_button"
android:track="@drawable/button_black" />

Thanks, bskania



 类似资料:

相关阅读

相关文章

相关问答