我想创建一个可绘制资源来更改图像按钮禁用时使用的图像。
我创建了一个可绘制资源
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/enabled_image" />
</item>
<item android:state_enabled="false">
<bitmap android:src="@drawable/disabled_image" />
</item>
</selector>
然后我在android:src="@drawable/resource"
中引用它。当我拨打ImageButton.setEnabled(false)
时,该按钮无法点击,但样式不会改变。
android:background
用于其他东西(半径颜色等)
答案 0 :(得分:2)
试试这个
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/disabled_backgroungd"/>
<item android:state_pressed="false"
android:drawable="@drawable/normal_backgroungd" />
<item android:state_pressed="true"
android:drawable="@drawable/backgroungd_selected" />
<item android:state_enabled="true" android:drawable="@drawable/normal_backgroungd"/>
</selector>
编辑:State List
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize=["true" | "false"]
android:dither=["true" | "false"]
android:variablePadding=["true" | "false"] >
<item
android:drawable="@[package:]drawable/drawable_resource"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_hovered=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_activated=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>
修改强>:
drawable中项目状态的顺序有所不同。
答案 1 :(得分:0)
if(!ImageButton.isEnabled())
{
//set the drawable
}