android switchcompat 颜色,Android SwitchCompat样式

我在装有Android 5.1.1的新设备上测试了我的应用程序.在我的SettingsActivity中,我有一个开关.我已经阅读了一些帖子,并将其更改为android.support.v7.widget.SwitchCompat,但问题仍然是:在我的旧设备上,开关看起来非常漂亮.您可以为textOn和textOff设置两个文本,它非常适合.但是自从api 21或其他我在这里得到这个小混蛋以来:

xIFfI.png

看起来像 ****.如何为棒棒糖开关等所有设备重新设置样式?

编辑:

上面的问题得到了回答.

缺少一件事:如何更改开关上文本的颜色(不是左侧的标签!!!)

styles.xml

12sp

#3F51B5

layout.xml

xmlns:app="http://schemas.android.com/apk/res-auto"

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="8dp"

android:paddingRight="8dp"

android:paddingBottom="12dp"

android:paddingTop="12dp">

android:id="@+id/mySwitch"

android:layout_width="match_parent"

android:switchMinWidth="56dp"

android:layout_height="wrap_content"

android:switchTextAppearance="@style/SwitchTextAppearance"

android:thumb="@drawable/thumb"

android:track="@drawable/track"

app:showText="true"

android:textOn="ON"

android:textOff="OFF"

android:text="Toggle Switch"

android:textAppearance="?android:attr/textAppearanceMedium"

android:background="@android:color/transparent"

android:button="@null"

android:layout_alignParentEnd="true"

android:layout_alignParentRight="true"/>

解决方法:

使用SwitchCompat.setSwitchTextAppearance可以设置出现在开关本身内部的文本的样式.

添加类似这样的样式并使用setSwitchTextAppearance进行设置:

12sp

#3F51B5

而且,您应该能够自定义“ OFF”文本的大小,颜色等.

标签:android,styles,switch-statement,switchcompat

来源: https://codeday.me/bug/20191012/1903077.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值