如何改变Android Switch轨道的宽度? [英] How to change Width of Android's Switch track?

查看:3391
本文介绍了如何改变Android Switch轨道的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个小问题感到很疯狂。我有一个'切换'表单小部件,但无论我尝试多少,我都不能让它更窄。即使我有一个字符而不是'ON'或'OFF',开关的大小也保持不变。 '拇指'变小,但必须拖动与之前相同的距离。将'layout_width'更改为较小的值只会切断剩余的轨道。 'minWidth'似乎什么也没做。

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代码:


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


我开始说:

但是我想要这样的东西:

but I want something like this:

推荐答案

在此属性中设置所需的开关宽度。

set your desired width of switch in this attribute.

android:switchMinWidth

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" />

谢谢,
bskania

Thanks, bskania

这篇关于如何改变Android Switch轨道的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆