【问题标题】:How to increase switch widget's thumb size in android? [duplicate]如何在android中增加开关小部件的拇指大小? [复制]
【发布时间】:2017-10-05 18:47:12
【问题描述】:

我正在使用开关小部件。这是代码

      <Switch
            android:id="@+id/switchFabric"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:showText="true"

           android:switchTextAppearance="@style/SwitchTextAppearance"
            android:text="Do you have fabric ?"
            android:textColor="@color/black_overlay"
            android:textOff="No"
            android:textOn="Yes"
            android:thumbTextPadding="@dimen/padding_4"
            android:padding="@dimen/padding_8"
            android:thumbTint="@color/white"
            android:layout_marginTop="@dimen/margin_10"
            android:layout_marginBottom="@dimen/margin_20"
            />

结果是这样的

我想增加拇指的大小,以便 Yes 文本周围有足够的填充。我试过用

thumbPadding

填充

开关最小宽度

如何做到这一点? 任何建议表示赞赏。提前致谢。

【问题讨论】:

    标签: android android-layout android-switch


    【解决方案1】:

    试试这样创建主题

    <style name="MySwitchStyle">
        <item name="android:textColor">#ffffff</item>
        <item name="android:textSize">15sp</item>
    </style>
    

    比适用于你的开关

     <Switch
            android:id="@+id/switchFabric"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:showText="true"
            android:switchTextAppearance="@style/SwitchTextAppearance"
            android:text="Do you have fabric ?"
            android:textColor="@color/black_overlay"
            android:textOff="No"
            android:textOn="Yes"
            android:scaleX="2"
            android:scaleY="2"
            android:thumbTextPadding="@dimen/padding_4"
            android:padding="@dimen/padding_8"
            android:thumbTint="@color/white"
            app:switchTextAppearance="@style/MySwitchStyle"
            android:layout_marginTop="@dimen/margin_10"
            android:layout_marginBottom="@dimen/margin_20"
            />
    

    【讨论】:

      【解决方案2】:

      我认为这应该对我有用

      <android.support.v7.widget.SwitchCompat
                  android:id="@+id/switch_compat2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_margin="20dp"
                  android:checked="true"
                  android:scaleX="2"
                  android:scaleY="2"
                  android:textOn="YES"
                  android:textOff="NO"
                  app:switchTextAppearance="@style/dd"
                  app:showText="true" />
      

      在你的styles.xml中添加下面几行

        <style name="dd">
              <item name="android:textColor">#ffffff</item>
              <item name="android:textSize">10sp</item>
          </style>
      

      根据需要调整文本大小和比例大小

      【讨论】:

      • 不,抱歉没有帮助。它只是增加了文本的大小。
      • 查看我编辑的答案
      猜你喜欢
      • 2018-05-07
      • 1970-01-01
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多