12

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

Brahadeesh
  • 2,245
  • 8
  • 40
  • 58

6 Answers6

20

@android:color/transparent. Phoenixblade9 was close.

Brahadeesh
  • 2,245
  • 8
  • 40
  • 58
15

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.

Codeman
  • 12,157
  • 10
  • 53
  • 91
  • It shows up with a black background now instead of grey. Both in my emulator and in motorola droidx. – Brahadeesh Aug 10 '11 at 20:19
  • That would be correct then, that is the default background color for most versions of Android. Perhaps if this isn't what you're looking for, you could post a screenshot and more description of your problem. – Codeman Aug 10 '11 at 20:21
  • Sorry. I did not mention it before. I have a background above which I have these buttons. Previously it was a grey bg behind the img and now its black. Hope you get it. I can post pictures if you want. – Brahadeesh Aug 10 '11 at 20:23
  • Please do post pictures, I'm not sure I understand what you're asking. Post them as an edit – Codeman Aug 10 '11 at 20:25
  • Sorry, I'm doing this off the top of my head. Give the new edit one more try. It should work this time :) – Codeman Aug 10 '11 at 20:46
  • 2
    Actually it is @android:color/transparent. Thank you for the help anyway. Please edit your answer. – Brahadeesh Aug 10 '11 at 20:51
  • Downvote for missing edit and therefore wrong answer. – James Cameron Nov 10 '14 at 21:20
  • 1
    @JamesCameron I think I omitted the edit because I didn't have the chance to test it myself, but I suppose if multiple people said it was that, I will trust it. I edited my answer to the correct one. – Codeman Nov 10 '14 at 23:50
5

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.

sivi
  • 10,654
  • 2
  • 52
  • 51
2

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"

suku
  • 10,507
  • 16
  • 75
  • 120
1

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.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Arjun Katwal
  • 247
  • 1
  • 3
  • 11
0

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.

ferhat
  • 1