【发布时间】:2011-08-09 07:54:44
【问题描述】:
默认情况下,单击按钮时,橙色之类的东西会在按钮周围短时间环绕,表示按钮已被单击。但是当按钮包含背景图像时,此功能不起作用。这也发生在列表视图中。为什么?有任何想法吗? TIA
我使用了 setBackgroundColor(Color.BLUE); 但是这里的颜色是应用的并且没有消失......
【问题讨论】:
默认情况下,单击按钮时,橙色之类的东西会在按钮周围短时间环绕,表示按钮已被单击。但是当按钮包含背景图像时,此功能不起作用。这也发生在列表视图中。为什么?有任何想法吗? TIA
我使用了 setBackgroundColor(Color.BLUE); 但是这里的颜色是应用的并且没有消失......
【问题讨论】:
我也有同样的问题。所以我没有设置背景颜色,而是包含了三种不同颜色的按钮的三个图像,所以根据状态聚焦,按下,默认相应的图像将替换另一个。而且看起来按钮的颜色发生了变化。
**<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/c2"
android:state_pressed="true" />
<item android:drawable="@drawable/c1"
android:state_focused="true" />
<item android:drawable="@drawable/c1" />
</selector>**
上面是xml文件的内容,必须分配给各个按钮的背景 android:background="@drawable/drawable_button
希望对你有帮助
【讨论】:
您需要使用选择器作为背景资源:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/button_pressed" />
<item android:state_focused="true" android:drawable="@drawable/button_focus" />
<item android:drawable="@drawable/button_normal" />
</selector>
此选择器使用 3 个独立的可绘制对象来更改按钮的图像,您可以使用相同的图像进行按下和聚焦。
您需要将此 XML 放入您的 drawables 目录,并将其用作按钮的背景。
【讨论】: