Android开关按钮颜色在4.0.4中未更改
我使用了切换按钮,当应用程序在4.2及以上版本上运行时,一切正常,但在4.0.4中,文本颜色根本没有变为白色。我尝试了所有可能的解决方案 我的开关:Android开关按钮颜色在4.0.4中未更改,android,button,switch-statement,textcolor,Android,Button,Switch Statement,Textcolor,我使用了切换按钮,当应用程序在4.2及以上版本上运行时,一切正常,但在4.0.4中,文本颜色根本没有变为白色。我尝试了所有可能的解决方案 我的开关: <Switch android:layout_width="100dp" android:layout_height="wrap_content" android:layout_below="@+id/facilityassetdescription" android:layou
<Switch
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="@+id/facilityassetdescription"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:background="@drawable/offbuttonbg"
android:textColor="@style/toggle_text"
android:textOff="OFF"
android:textOn="ON"
android:thumb="@drawable/switchselector" />
我的样式文件
<style name="toggle_text">
<item name="android:textColor">@color/toggle</item>
</style>
@颜色/切换
res/color/toggle_text.xml
<?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"/>
<!-- Default State -->
<item android:color="#ffffff"/>
</selector>
请给出解决此问题的任何想法使用以下样式:
<style name="toggle_text" parent="@android:style/TextAppearance.Small">
<item name="android:textColor">@color/toggle</item>
</style>
@颜色/切换
并且,在交换机的xml文件中提到android:switchTextAppearance属性,而不是使用android:textColor:
<Switch
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="@+id/facilityassetdescription"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:background="@drawable/offbuttonbg"
android:switchTextAppearance="@style/toggle_text"
android:textOff="OFF"
android:textOn="ON"
android:thumb="@drawable/switchselector" />
使用支持7 SwitchCompat 把
#e21d
放在你的风格里
和主题中的#e21d
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="5dp"
app:showText="false" >
</android.support.v7.widget.SwitchCompat>
祝你好运
您可以使用Switch Compat,也可以使用支持v7的Switch
图书馆。尝试新概念
my.xml
<android.support.v7.widget.SwitchCompat
android:id="@+id/sc_push"
style="@style/switchStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:theme="@style/switchStyle"
app:theme="@style/switchStyle" />
<style name="switchStyle">
<item name="colorControlActivated">@color/red</item>
<item name="android:colorForeground">@color/gray</item>
</style>
style.xml
<android.support.v7.widget.SwitchCompat
android:id="@+id/sc_push"
style="@style/switchStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:theme="@style/switchStyle"
app:theme="@style/switchStyle" />
<style name="switchStyle">
<item name="colorControlActivated">@color/red</item>
<item name="android:colorForeground">@color/gray</item>
</style>
@颜色/红色
@颜色/灰色
祝你好运
如果上述答案不起作用,请尝试以下方法
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_is_in_stock"
style="@style/proximaNovaNormalColorBlack.size14"
android:layout_width="0dp"
android:layout_height="0dp"
android:maxLines="1"
android:padding="4dp"
android:textColor="@color/switch_thumb_selector"/>
答案在这条xml行->android:textColor=“@color/switch\u thumb\u selector”这两种颜色都是白色的?您是否通过更改其中一种颜色进行检查?此处两种颜色都显示为黑色。与其使用白色,不如尝试为文本颜色属性指定可绘制的颜色,而不是颜色。将toggle_text.xml放在drawable文件夹中,设置textColor=“@drawable/toggle_text”并查看它是否有效。是的,当然,让我检查一下你是否尝试给android:textColor=“#FFFFFF”?很好,它有效。android:switchTextAppearance=“@style/toggle_text”答案是这一行,对吗?