android how to change text color for "textOFF" for switch?

41 views Asked by At

I am using a switch in my android application as below:

  <Switch
            android:id="@+id/it_radio_group"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:showText="true"
            android:textOff="NON"
            android:textOn="OUI"
            android:switchTextAppearance="@style/SwitchTextAppearance"
            android:thumb="@drawable/rectangle_switch_thumb"
            android:track="@drawable/rectangle_switch" />

and below the drawables used for thumb and track:

for thumb

for track:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp" android:color="@color/colorPrimary"/>
<solid android:color="@color/white" />
<corners android:radius="0dp" /> 

for style SwitchTextAppearance

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" android:state_checked="true" />
<item android:color="@color/colorPrimary" android:state_checked="false" />
</selector>

the problem is in the color of text of OFFtext, it is not changed to colorPrimary as in the switchTextAppearance style note that the track and the thumb are working well how to change the color of the text in offText of switch ?

0

There are 0 answers