Android 开关 - 使拇指高度大于轨道高度,如何?

标签 android android-switch

在 Lollipop 之前的 Android 版本中,有什么方法可以使开关的拇指高度大于轨道高度?

我基本上是在尝试在 Kitkat 中创建一个类似 Material 设计的开关小部件(和旧版本 - 这里的问题是默认情况下拇指“适合”在轨道内)。我已经为此工作了很长一段时间,但我似乎无法得出正确的设计。

我遵循了这篇 SO 帖子中的解决方案:How to change the size of a Switch Widget .

如有任何建议或解决方案,我们将不胜感激。

最佳答案

我向我的轨道可绘制形状添加了一个透明笔触,这导致轨道周围出现填充:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid android:color="@color/track_color"/>
    <size android:height="@dimen/track_height"  />
    <size android:width="@dimen/track_width"  />

    <!-- results in the track looking smaller than the thumb -->
    <stroke
        android:width="6dp"
        android:color="#00ffffff"/>
</shape>

关于Android 开关 - 使拇指高度大于轨道高度,如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29115057/

相关文章:

android - setCompoundDrawables 与 RemoteViews

android - 按时间间隔更改 margin 值

android - Google Play 因不安全的加密模式而拒绝我的应用

Android 在 onCheckedChangeListener 中设置开关状态

Android在迭代时切换开关按钮

android - 如何设计 Android Switch?

android - 在android中缩小图像时找不到点的位置

android - 我可以为两个不同的应用程序使用相同的 Firebase 吗?

android - 切换按钮未显示在 ActionBar 中?

android - 如何设置开关的回收 View 以在每个开关上执行不同的功能