ImageButton doesn't highlight on click with Transparent background

Stealth Rabbi picture Stealth Rabbi · Oct 10, 2012 · Viewed 34.5k times · Source

I've set up an ImageButton to be transparent, so the icon matches the backgrond panel like the Android ActionBar. This looks fine as I want it to.

However, when the background is transparent, there isn't the blueish highlight you see as when you press a transparent button in the action bar.

Can I have an ImageButton that is transparent and also has the highlight flash when clicked?

<ImageButton
    android:id="@+id/nextItemButton"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@null"
    android:src="@drawable/ic_media_ff" />

Answer

Fernandez picture Fernandez · Dec 13, 2012

I came across this same problem. Finally, I got a sample of a code with that attribute:

android:background="?android:selectableItemBackground"

This attibute will give a transparent background with selectable highlight to any View (Button, ImageButton, TextView...) WITHOUT MORE CODING!!!