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
Switch on screenshot
Switch on image
Switch off image
Thumb image
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"