如何更改 Android 开关小部件的缩略图 (ON/OFF) 的文本颜色?
How can I change the Text color of the thumb(ON/OFF) for Android Switch widget?
我尝试设置 textAppearanceAttribute。但它不起作用。
还有另一个属性 textColor 但这是用于开关的标签。
<Switch
android:id="@+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/double_margin"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textAppearance="@style/SwitchTextAppearance"
android:track="@drawable/transit_switch_track"
android:thumb="@drawable/transit_switch_thumb" />
<style name="SwitchTextAppearance">
<item name="android:textColor">@android:color/red</item>
</style>
我通过使用可绘制对象解决了这个问题,而不是尝试 fiddle 使用颜色。
代码如下:
<Switch
android:id="@+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/double_margin"
android:switchMinWidth="50dp"
android:textOff=""
android:textOn=""
android:thumb="@drawable/switch_thumb"
android:track="@drawable/switch_track"
android:checked="false" />
switch_track.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/switch_off" android:state_checked="false"/>
<item android:drawable="@drawable/switch_on" android:state_checked="true"/>
</selector>
switch_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/toggle" android:state_enabled="false"/>
<item android:drawable="@drawable/toggle" android:state_pressed="true"/>
<item android:drawable="@drawable/toggle" android:state_checked="true"/>
<item android:drawable="@drawable/toggle"/>
</selector>
这是我的 Switch 现在的样子:
Switch_off 图片
Switch_on 图片
切换只是拇指的白色图像。
我尝试设置 textAppearanceAttribute。但它不起作用。 还有另一个属性 textColor 但这是用于开关的标签。
<Switch
android:id="@+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/double_margin"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textAppearance="@style/SwitchTextAppearance"
android:track="@drawable/transit_switch_track"
android:thumb="@drawable/transit_switch_thumb" />
<style name="SwitchTextAppearance">
<item name="android:textColor">@android:color/red</item>
</style>
我通过使用可绘制对象解决了这个问题,而不是尝试 fiddle 使用颜色。
代码如下:
<Switch
android:id="@+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/double_margin"
android:switchMinWidth="50dp"
android:textOff=""
android:textOn=""
android:thumb="@drawable/switch_thumb"
android:track="@drawable/switch_track"
android:checked="false" />
switch_track.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/switch_off" android:state_checked="false"/>
<item android:drawable="@drawable/switch_on" android:state_checked="true"/>
</selector>
switch_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/toggle" android:state_enabled="false"/>
<item android:drawable="@drawable/toggle" android:state_pressed="true"/>
<item android:drawable="@drawable/toggle" android:state_checked="true"/>
<item android:drawable="@drawable/toggle"/>
</selector>
这是我的 Switch 现在的样子:
Switch_off 图片
Switch_on 图片
切换只是拇指的白色图像。