Reputation: 1800
I have used Switch button, everything works fine when the app run it on 4.2 and above, but the text color not at all changed to white in 4.0.4 i have tried all possible solution
My Switch :
<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" />
My style file
<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>
Kindly give any idea to get rid of this problem
Upvotes: 0
Views: 2398
Reputation: 1012
for anyone if the above answers did not work try this..
<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"/>
answer is on this xml line -> android:textColor="@color/switch_thumb_selector"
Upvotes: 0
Reputation: 2215
You can use Switch-Compat intend of Switch using support v7 library.Try new concept
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.xml
<style name="switchStyle"> <item name="colorControlActivated">@color/red</item> <item name="android:colorForeground">@color/gray</item> </style>
Best of luck
Upvotes: 4
Reputation: 1684
Use support 7 SwitchCompat
and put <item name="colorSwitchThumbNormal">#E21D1D</item>
in your style
and <item name="colorSwitchThumbNormal">#E21D1D</item>
in your theme
<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>
Gud Luck!!
Upvotes: 1
Reputation: 526
Use below style:
<style name="toggle_text" parent="@android:style/TextAppearance.Small">
<item name="android:textColor">@color/toggle</item>
</style>
And, In xml file for switch mention android:switchTextAppearance attribute instead of using 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" />
Upvotes: 2