user3669034 user3669034 - 1 year ago 511
Android Question

How to change indicator color in Toggle Button ( Android)

Hi every body I want to use toggle button but with different indicator color (like green or red), How to change the color of indicator .

enter image description here

Answer Source

I think you are going to have to create 2 custom images of the button and then use a drawable xml as the background.

For Example:

    android:textOff="Toggle Button OFF"
    android:textOn="Toggle Button ON "

Then the btntoggle_selector xml

<?xml version="1.0" encoding="utf-8"?>

<item android:drawable="@drawable/bg_selected" android:state_checked="true" android:state_pressed="true"/>
<item android:drawable="@drawable/bg_selected" android:state_checked="true" android:state_focused="false"/>
<item android:drawable="@drawable/bg_normal" android:state_checked="false" android:state_pressed="true"/>
<item android:drawable="@drawable/bg_normal" android:state_checked="false" android:state_focused="false"/>

bg_selected and bg_normal are just images like 9-patch.

See the Android developer guide on 9-patch images

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download