Brahadeesh
Brahadeesh

Reputation: 2255

png image showing up with grey background in android

I have some png image buttons that I use in my app. But they are showing up with grey backgrounds on my page. Does android always show a grey background for a transparent one? Is there a work around?
This is how it showed before.

enter image description here
This is how it shows after I made #FF000000 edits

enter image description here


This is how I want it to show.
EDIT:
Error when I use #FF:
Color value not valid -- must be #rgb, #argb, #rrggbb, or #aarrggbb (at 'background' with value '#FF'). main.xml

Upvotes: 12

Views: 29487

Answers (6)

Arjun Katwal
Arjun Katwal

Reputation: 257

Please check whether your image is 32 bit depth or not. After that insert this code in your image view: android:background="@android:color/transparent". To make your image transparent open Adobe Photoshop or Illustrator, open file (i.e. your image) and click file and click to export - save as web (legacy), tick transparent and save it.

Upvotes: 1

suku
suku

Reputation: 10929

I found this happens if you have android:src="@drawable/mypngimage" in your xml file. Instead if you use background then the gray area goes away and it behaves as expected. android:background="@drawable/mypngimage"

Upvotes: 2

Codeman
Codeman

Reputation: 12375

If the image is transparent, there should be nothing shown behind the image.

The default colors vary from distribution to distribution. The color scheme/theme for an HTC phone will be different than from a Motorola phone, or the emulator.

If you want to ensure that a view has a transparent background, set the following in your XML code for that view:

android:background="@android:color/transparent"

This should ensure the background is completely transparent.

Upvotes: 15

sivi
sivi

Reputation: 11114

The code line in the ImageView or ImageButton in the XML file is actually:

android:background="@android:color/transparent"

I am writing this to help someone who is not familiar with the platform and won't connect the two answers above.

Upvotes: 5

ferhat
ferhat

Reputation: 1

Also you can use #50FFFFFF (aarrggbb). in this format, aa is alpha channel to be transparency frequency. So If you use above color, you get a 50% transparent white background.

Upvotes: 0

Brahadeesh
Brahadeesh

Reputation: 2255

@android:color/transparent. Phoenixblade9 was close.

Upvotes: 20

Related Questions