Skip to content Skip to sidebar Skip to footer

Custom Switch In Android With Text In Track

I have a custom switch. I want the text (on/off) to be in the track and not in the thumb. I was thinking of setting a selector with text in drawable and setting it as track of the

Solution 1:

Switch off screenshot

enter image description here

Switch on screenshot

enter image description here

Switch on image

enter image description here

Switch off image

enter image description here

Thumb image

enter image description here

switch_on_off.xml

<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_checked="true"android:drawable="@drawable/on_switch"/><itemandroid:state_checked="false"android:drawable="@drawable/off_switch"/><itemandroid:drawable="@drawable/off_switch"/></selector>

xml code

<android.support.v7.widget.SwitchCompat
    android:id="@+id/switch_compat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    app:track="@drawable/switch_on_off"
    android:thumb="@drawable/on_switch_active"/>

Try above code and let me know if you find any error.....

Post a Comment for "Custom Switch In Android With Text In Track"