Question

I'm having a bizarre problem with standard android Switch component.

I've assigned my custom tracker and thumb drawables - everything seems to look and work ok, except the the color of the textColor attribute which is always dark (possibly theme color).

Tried to assign color in hex, as a resource, and as a selector through the android:textColor attribute. Unfortunately every effort fails to achieve the goal of changing

Did anyone came across this problem?

Here's my usage:

<Switch
    android:id="@id/settings_lock_screen_compound_btn"
    android:layout_width="97dp"
    android:layout_height="24dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:textOff="Off"
    android:textOn="On"
    android:textSize="12sp"
    android:thumb="@drawable/switch_thumb"
    android:track="@drawable/switch_track_bg" />
Was it helpful?

Solution

Turns out, you've got to use switchTextAppearance and define textAppeareance attribute in style resources to change (or do equivalent in your java code).

The textColor attribute in Switch class is pretty misleading in this case but necessary as the class inherits (not directly) from TextView class

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top