将图像设置为背景时,向按钮添加发光

时间:2011-11-14 19:10:45

标签: android image button

通常clik上的按钮填充橙色。当我将某些图像设置为按钮的背景时,clik上没有任何操作。我想在按下按钮时添加一些发光。

1 个答案:

答案 0 :(得分:1)

使用StateListDrawable。将其键入文件并将其存储为 res / drawable / button_bg.xml 。然后创建4个图像(button_press.png,button_focus.png,button_disabled.png和button.png),最后将背景设置为button_bg

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_press" android:state_pressed="true" />
    <item android:drawable="@drawable/button_focus" android:state_focused="true" />
    <item android:drawable="@drawable/button_disabled" android:state_enabled="false" />
    <item android:drawable="@drawable/button" />
</selector>

这背后的“神奇”就是android将从上到下使用第一个匹配你的按钮状态。