如何添加图像按钮单击效果?

时间:2014-02-20 05:16:45

标签: android onclick imagebutton

我正在使用android。我想在ImageButton上添加onClick()效果,最好是选中后按钮两侧的颜色。我尝试过使用alpha效果。但是在点击后回来后它看起来很黑。

如何添加ImageButton点击效果?

1 个答案:

答案 0 :(得分:3)

你可以使用如下的选择器xml: -

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_pressed_yellow"
          android:state_pressed="true" />
    <item android:drawable="@drawable/button_focused_orange"
          android:state_focused="true" />
    <item android:drawable="@drawable/button_normal_green" />
</selector>

并将其设置为按钮的background