Eggy
Eggy

Reputation: 551

Transparent picture in ImageButton does not display transparency

This is my transparent image:

enter image description here

But when I apply it to my app, the image not transparent, as shown below:

enter image description here

Why would the following code produce this behaviour?

<ImageButton
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:id="@+id/back"
    android:layout_gravity="center_vertical"
    android:src="@drawable/back"/>

Activity:

ImageButton back = (ImageButton) findViewById(R.id.back);
back.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Back();
    }
});

Upvotes: 2

Views: 971

Answers (5)

Eggy
Eggy

Reputation: 551

i have try android:background="@null"but it's not have changes for me

so i try to clean project and rebuild project and then remove my app from phone and it's work :) Thanks to other who try help me your answer is really help me :)

and this my final code

<ImageButton
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:id="@+id/back"
                        android:src="@drawable/back"
                        android:background="@null"
                        android:layout_gravity="center_vertical"/>

Upvotes: 2

Arjun saini
Arjun saini

Reputation: 4182

Try this

you are use the direct drawable instead of src

  <ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:background="@drawable/back"

   />

Note: if Your back image is white than should be your main layout or back ImageButton back layout background not white....

Upvotes: 0

Angel Koh
Angel Koh

Reputation: 13485

you can try this

<ImageButton
  android:layout_width="30dp"
  android:layout_height="30dp"
  android:id="@+id/back"
  android:layout_gravity="center_vertical"
  android:src="@drawable/back" 
  android:background="@android:color/transparent"/>

if it does not work, try setting a background to another color (just to make sure that the src image is pointing to the correct drawable)

edit: also remove all tints if you have them, to see if it affects the results.

Upvotes: 0

Sathish Kumar J
Sathish Kumar J

Reputation: 4335

You need to set android:background = "@null"

  <ImageButton 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:src="@drawable/ic_action_exit"
  android:background="@null"/>

put your drawable name instead of ic_action_exit.

this should give transparent background.

Screenshot

Screenshot

Screenshot 2

screenshot2

My Image

back_icon

Upvotes: 0

Dhruvi
Dhruvi

Reputation: 1981

Write below line in your ImageButton:

android:background="@null"
android:src="YOUR_IMAGE"

Upvotes: 0

Related Questions