【发布时间】:2014-02-20 05:16:45
【问题描述】:
我正在使用安卓系统。我想在 ImageButton 上添加onClick() 效果,最好是选择后按钮两侧的颜色。我曾尝试使用 alpha 效果。但即使点击后返回,它看起来也很暗。
如何添加ImageButton点击效果?
【问题讨论】:
-
您能分享您的代码和屏幕截图,说明您已经取得的成就和您想要的吗?
标签: android onclick imagebutton
我正在使用安卓系统。我想在 ImageButton 上添加onClick() 效果,最好是选择后按钮两侧的颜色。我曾尝试使用 alpha 效果。但即使点击后返回,它看起来也很暗。
如何添加ImageButton点击效果?
【问题讨论】:
标签: android onclick imagebutton
您可以使用如下选择器 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>
并将其设置为您的 Button 的 background。
【讨论】: