Android, Hide stock toggle when using custom backg

2019-06-08 01:33发布

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.

1条回答
疯言疯语
2楼-- · 2019-06-08 02:07

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

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

查看更多
登录 后发表回答