Mad*_*dhu 0 android button textcolor switch-statement
我已经使用了Switch按钮,当应用程序在4.2及更高版本上运行时,一切正常,但4.0.4中的文本颜色根本没有变为白色我尝试了所有可能的解决方案
我的开关:
<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" />
Run Code Online (Sandbox Code Playgroud)
我的样式文件
<style name="toggle_text">
<item name="android:textColor">@color/toggle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
RES /颜色/ 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>
Run Code Online (Sandbox Code Playgroud)
请任何想法摆脱这个问题
您可以使用支持v7库来使用Switch的Switch-Compat打算.尝试新概念
my.xml
Run Code Online (Sandbox Code Playgroud)<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.xml
Run Code Online (Sandbox Code Playgroud)<style name="switchStyle"> <item name="colorControlActivated">@color/red</item> <item name="android:colorForeground">@color/gray</item> </style>
祝你好运
归档时间: |
|
查看次数: |
2121 次 |
最近记录: |