views:

423

answers:

1

Is there a way to highlight an ImageButton when it's pressed?

+3  A: 

You can define a drawable via XML and use the selector, like below, to use different (i.e. highlighted) images for different button states:

i.e. res/drawable/button.xml:

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

    <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>

Use this resource then for the ImageButton view.

Mathias Lin
I was typing the same answer but you got there first..
primalpop