[英]Change switch button text color
我可以使用Github的Switch Button Demo類中提供的以下自定義類在我的應用程序中成功創建一個switch button
這是我得到的快照
除了一件事,一切都很好,我想將文本顏色設為未經檢查的黑色狀態。 我的意思是未選中時, “ OFF”文本顏色為黑色。 我試圖在自定義類上添加一些條件,但是並沒有給我適當的結果。 我的style.xml文件是這樣的
<style name="mySwitchStyle">
<item name="track">@drawable/switch_track_green</item>
<item name="thumb">@drawable/background_fenced</item>
<item name="switchTextAppearanceAttrib">@style/mySwitchTextAppearance</item>
<item name="textOn">ON</item>
<item name="textOff">OFF</item>
<item name="pushStyle">false</item>
<item name="textOnThumb">true</item>
<item name="thumbExtraMovement">0dp</item>
<item name="thumbTextPadding">6dp</item>
<item name="trackTextPadding">6dp</item>
<item name="switchMinWidth">69dp</item>
<item name="switchMinHeight">36dp</item>
<item name="switchPadding">6dp</item>
</style>
<style name="mySwitchTextAppearance">
<item name="textColor">#FFeeFFee</item>
<item name="textColorHighlight">#FFeeFFee</item>
<item name="textColorHint">#FFeeFFee</item>
<item name="textColorLink">#FFeeFFee</item>
<item name="textSize">16sp</item>
<item name="textStyle">normal</item>
</style>
我試圖將textColorHighlight,textColorHint,textColorLink更改為黑色,但沒有給我想要的結果。 請幫助我達到期望的結果。
您需要將textColor
定義為顏色列表
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:color="#ffffff"/> <!-- checked, white -->
<item android:color="#000000"/> <!-- default, black -->
</selector>
更新:
SwitchCompat是Switch小部件的一個版本,在設備上可返回API v7。 它不會嘗試在正常可用的那些設備上使用平台提供的窗口小部件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.