Android, Hide stock toggle when using custom background?

自闭症网瘾萝莉.ら 提交于 2019-12-08 04:02:15

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!