4

Problem:

I have saved a png image into the @drawable folder in android studio. This image is confirmed to have an alpha channel.

Image in android studio: enter image description here

When I add it to an image view in a relative layout the alpha channel is lost

ImageView image:

enter image description here

xml layout code:

<ImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    app:srcCompat="@drawable/icon_main"
    android:id="@+id/main_icon_img"
    android:background="@android:color/transparent"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    android:layout_marginLeft="31dp"
    android:layout_marginStart="31dp"
    android:layout_marginTop="113dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

I have tried setting the background to transparent. If I save it to a mipmap then the image will show the alpha channel, although this is not my preferred method.

Is there a reason to why its appearing with a white background?

user2853442
  • 331
  • 5
  • 15

2 Answers2

1

For me the problem was

<item name="android:background">@color/white</item>

in the theme style. This made all the views to be drawn with a white BG. Even theTextViews.

Saran Sankaran
  • 2,335
  • 2
  • 19
  • 34
0

Please check the imageView if it has a background attribute and get rid of it as shown on this image

enter image description here

I also found this site to be so helpful to enable you easily remove background from the image effectively making it PNG

Tonnie
  • 4,865
  • 3
  • 34
  • 50