2017-10-05 73 views
-1

我正在使用開關小部件。這裏是代碼如何在android中增加開關部件的拇指大小?

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

它出來是這個

enter image description here

我想增加拇指的大小,以便有文字周圍有足夠的填充。我曾嘗試與

thumbPadding

填充試驗

switchMinWidth

如何實現這一目標? 任何建議表示讚賞。提前致謝。

回答

0

試試這個創建主題類似這樣的

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

我想這應該做它爲我工作

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

根據需要調整文本大小和縮放大小

+1

沒有抱歉,它沒有幫助。它只是增加了文本的大小。 –

+0

結帳我編輯的答案 –

相關問題