Android, Hide stock toggle when using custom background?
Asked Answered
E

1

1

I've got a custom drawable for my toggle switch

// toggle_selector.xlm
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/toggle_on" android:state_checked="true"/>
    <item android:drawable="@drawable/toggle_off" android:state_checked="false"/>
</selector>

Which I then apply to the switch

    <Switch
        android:id="@+id/geoLocationsToggle"
        android:background="@drawable/toggle_selector"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:textOff=""
        android:textOn=""
        android:textSize="0dp" />

But the original (stock) toggle still shows overtop the custom background

Toggle

How do I get rid of the stock switch on top of my custom one?

Thanks in advance.

Early answered 22/10, 2015 at 21:19 Comment(0)
G
2

You should use android:thumb and android:track, not android:background

And you should write a selector for each one of them.

Gaivn answered 22/10, 2015 at 21:28 Comment(1)
Also worked to just set the thumb and track to transparent, and then continue using the BG image I previously made.Early

© 2022 - 2024 — McMap. All rights reserved.