默认开关与自定义开关重叠
Default Switch overlapping with Custom Switch
我正在尝试分别使用两个图像作为 false 和 true 来实现自定义开关。但问题是默认开关图像与自定义开关图像重叠。
下面是我的 Switch 代码:
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you want the current offer as your final offer"
android:background="@null"
android:button="@null"
android:textOff=""
android:textOn=""
android:drawableRight="@drawable/switch"
android:textSize="16sp"
android:textColor="#9B9B9B"
android:id="@+id/switch1"
/>
下面是我的switch.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/dummy_toggle_off"
android:state_checked="false" />
<item
android:drawable="@drawable/dummy_toggle_on"
android:state_checked="true" />
<item
android:drawable="@drawable/dummy_toggle_off"/>
</selector>
这是生成的图像:
开关定制使用如下代码-
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="@drawable/switch_thumb"
android:track="@drawable/switch_track" />
此处 switch_thumb
是 样式 xml 文件用于您的 thumb
并且 switch_track
是您的 xml 样式对于 background
的开关。
有关详细信息,请参阅 link-link
switch_thumb.xml
<selector>
<item android:drawable="@drawable/your_png_for_thumb">
</item>
</selector>
switch_track.xml
<selector>
<item android:drawable="@drawable/your_png_for_track_grey"
android:state_checked="true"/>
<item android:drawable="@drawable/your_png_for_track_blue"
android:state_checked="false"/>
</selector>
你可以从网上下载这些 png 图像..下面是一个 link 你可以在那里找到那些 png-icon finder
I have the same problem and I think this solution.
在您的 XML 开关中添加此代码。
android:thumb="@android:color/transparent"
android:track="@android:color/transparent"
android:background="@drawable/yourSelector"
我正在尝试分别使用两个图像作为 false 和 true 来实现自定义开关。但问题是默认开关图像与自定义开关图像重叠。
下面是我的 Switch 代码:
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you want the current offer as your final offer"
android:background="@null"
android:button="@null"
android:textOff=""
android:textOn=""
android:drawableRight="@drawable/switch"
android:textSize="16sp"
android:textColor="#9B9B9B"
android:id="@+id/switch1"
/>
下面是我的switch.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/dummy_toggle_off"
android:state_checked="false" />
<item
android:drawable="@drawable/dummy_toggle_on"
android:state_checked="true" />
<item
android:drawable="@drawable/dummy_toggle_off"/>
</selector>
这是生成的图像:
开关定制使用如下代码-
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="@drawable/switch_thumb"
android:track="@drawable/switch_track" />
此处 switch_thumb
是 样式 xml 文件用于您的 thumb
并且 switch_track
是您的 xml 样式对于 background
的开关。
有关详细信息,请参阅 link-link
switch_thumb.xml
<selector>
<item android:drawable="@drawable/your_png_for_thumb">
</item>
</selector>
switch_track.xml
<selector>
<item android:drawable="@drawable/your_png_for_track_grey"
android:state_checked="true"/>
<item android:drawable="@drawable/your_png_for_track_blue"
android:state_checked="false"/>
</selector>
你可以从网上下载这些 png 图像..下面是一个 link 你可以在那里找到那些 png-icon finder
I have the same problem and I think this solution.
在您的 XML 开关中添加此代码。
android:thumb="@android:color/transparent"
android:track="@android:color/transparent"
android:background="@drawable/yourSelector"