Android Switch 修改文字颜色

2019-12-13  本文已影响0人  Lost_Robot
通常的Switch默认按钮

此时默认的文字颜色是黑色的。

想要修改文字的颜色:
1.在Style文件中添加style:

 <style name="switch_text_color_white" parent="@android:style/TextAppearance.Small">
        <item name="android:textColor">@color/colorWhite</item>
    </style>

2.使用

  android:switchTextAppearance="@style/switch_text_color_white"
设置背景和文字的颜色
  <Switch
        android:layout_width="70dp"
        android:layout_height="25dp"
        android:background="@drawable/bg_a"
        android:drawableEnd="@drawable/down_icon"
        android:drawablePadding="5dp"
        android:gravity="end|center"
        android:paddingStart="0dp"
        android:paddingEnd="10dp"
        android:showText="true"
        android:switchTextAppearance="@style/switch_text_color_white"
        android:text="@string/account_str"
        android:thumb="null"
         />

上一篇 下一篇

猜你喜欢

热点阅读