Android突出显示ImageButton onclick

Chr*_*ris 3 android onclick highlight imagebutton

有没有办法突出显示ImageButton何时被按下?

Mat*_*adt 13

您可以通过XML定义drawable并使用选择器(如下所示)为不同的按钮状态使用不同的(即突出显示的)图像:

即res/drawable/button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/bg_catlocfilter" android:state_pressed="false" />
    <item android:drawable="@drawable/bg_catlocfilter_dark" android:state_pressed="true" />
    <item android:drawable="@drawable/bg_catlocfilter" android:state_focused="false" />
    <item android:drawable="@drawable/bg_catlocfilter_dark" android:state_focused="true" />

</selector>
Run Code Online (Sandbox Code Playgroud)

然后将此资源用于ImageButton视图.