2013-03-19 98 views
1

我添加了自定义切换按钮,它工作正常。 问题是,切换按钮启用和禁用。 我需要一个不同的布局按钮,关闭按钮,禁用&按钮,启用&按钮,关闭按钮&禁用并关闭按钮&启用。 这里是开/关的代码。 怎么办?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> 

回答

1

我没有这样做之前,但因为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:[email protected]/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_enab led.xml,但包含禁用Button的外观..