How to have a transparent ImageButton: Android
<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.
Try using null for the background ...
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:
Read more... Read less...
You can also use a transparent color:
Setting the background to
"@null" will make the button have no effect when clicked. This will be a better choice.
Later I found that using
is also a good solution. And you can inherit this attribute in your own style.
in run time, you can use following code
I believe the accepted answer should be:
This is the same as @lory105's answer but it uses the support library for maximum compatibility (the
android: equivalent is only available for API >= 11)
Remove this line :
And in your activity class set
ImageButton btn = (ImageButton)findViewById(R.id.previous); btn.setAlpha(100);
You can set alpha level 0 to 255
o means transparent and 255 means opaque.