[英]custom Toggle button in android
我添加了一个自定义切换按钮,效果很好。 问题是启用和禁用切换按钮。 我需要按钮打开,按钮关闭,按钮打开和禁用,按钮打开和启用,按钮关闭和禁用以及按钮关闭和启用的不同布局。 这是开/关的代码。 怎么做 ??
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<bitmap android:src="@drawable/button_pause_pressed"
android:gravity="center_vertical|center_horizontal" />
</item>
<item android:state_checked="false">
<bitmap android:src="@drawable/button_play_pressed_new"
android:gravity="center_vertical|center_horizontal" />
</item>
</selector>
我之前没有做过,但是由于StateList是可绘制的,因此可能可以引用另一个包含选择器的 XML文件。
看起来像这样...
button.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:drawable="@drawable/button_enabled"/>
<item android:drawable=@drawable/button_disabled/>
</selector>
button_enabled.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<bitmap android:src="@drawable/button_pause_pressed"
android:gravity="center_vertical|center_horizontal" />
</item>
<item android:state_checked="false">
<bitmap android:src="@drawable/button_play_pressed_new"
android:gravity="center_vertical|center_horizontal" />
</item>
</selector>
button_disabled.xml看起来像button_enabled.xml ,但是包含禁用Button的外观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.