How to have a transparent ImageButton: Android


Question

<ImageButton android:id="@+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/media_skip_backward"
android:background="@drawable/transparent"></ImageButton>

This is what I tried to get a transparent ImageButton so as to place those buttons on a SurfaceView. But Eclipse, gives me an error in the project as soon as I include the transparent line in xml.

Please help.

1
469
8/4/2010 5:15:18 AM

Accepted Answer

Try using null for the background ...

android:background="@null"
952
8/4/2010 5:17:43 AM

DON'T USE A TRANSAPENT OR NULL LAYOUT because then the button (or the generic view) will no more highlight at click!!!

I had the same problem and finally I found the correct attribute from Android API to solve the problem. It can apply to any view.

Use this in the button specifications:

android:background="?android:selectableItemBackground"

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon