Android: toggle text color of ToggleButton Android: toggle text color of ToggleButton android android

Android: toggle text color of ToggleButton


Create a similar state list for the text colors you would like, and place it in res/color, e.g.

res/color/toggle_color.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="#070" />    <!-- Default State -->    <item android:color="#A00" /></selector>

Then set this resource as the text color of the button:

<item name="android:textColor">@color/toggle_color</item>

P.S., it's good practice to have the last item in a selector not have any state flags attached (i.e. a default state) rather than defining it with the inverse of the above states.