The best way is using the transparent color code
android:background="#00000000"
use the color code #00000000 for making any thing transparent
I was already adding something to the background so , This thing worked for me:
android:backgroundTint="@android:color/transparent"
(Android Studio 3.4.1)
EDIT: only works on android api level 21 and above. for compatibility, use this instead
android:background="@android:color/transparent"
Remove this line :
android:background="@drawable/transparent">
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.
Programmatically it can be done by :
image_button.setAlpha(0f) // to make it full transparent
image_button.setAlpha(0.5f) // to make it half transparent
image_button.setAlpha(0.6f) // to make it (40%) transparent
image_button.setAlpha(1f) // to make it opaque
Use this:
<ImageButton
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:padding="10dp"
android:src="@drawable/backbtn" />
<ImageButton
android:id="@+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/media_skip_backward">
</ImageButton>
I used a transparent png
for the ImageButton
, and the ImageButton
worked.