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
How do I get rid of the stock switch on top of my custom one?
Thanks in advance.
You should use android:thumb
and android:track
, not android:background
And you should write a selector
for each one of them.
来源:https://stackoverflow.com/questions/33290945/android-hide-stock-toggle-when-using-custom-background