简体   繁体   English

png 图像在 android 中显示为灰色背景

[英]png image showing up with grey background in android

I have some png image buttons that I use in my app.我有一些在我的应用程序中使用的 png 图像按钮。 But they are showing up with grey backgrounds on my page.但是它们在我的页面上显示为灰色背景。 Does android always show a grey background for a transparent one? android 是否总是为透明的显示灰色背景? Is there a work around?有解决办法吗?
This is how it showed before.这是之前表现出来的。

在此处输入图像描述
This is how it shows after I made #FF000000 edits这是我进行#FF000000 编辑后的显示方式

在此处输入图像描述


This is how I want it to show.这就是我希望它显示的方式。
EDIT:编辑:
Error when I use #FF:使用#FF 时出错:
Color value not valid -- must be #rgb, #argb, #rrggbb, or #aarrggbb (at 'background' with value '#FF').颜色值无效 - 必须是 #rgb、#argb、#rrggbb 或 #aarrggbb(在“背景”,值为“#FF”)。 main.xml main.xml

@android:color/transparent. @android:颜色/透明。 Phoenixblade9 was close. Phoenixblade9 很接近。

If the image is transparent, there should be nothing shown behind the image.如果图像是透明的,则图像后面不应显示任何内容。

The default colors vary from distribution to distribution.默认 colors 因发行版而异。 The color scheme/theme for an HTC phone will be different than from a Motorola phone, or the emulator. HTC 手机的配色方案/主题将不同于摩托罗拉手机或模拟器。

If you want to ensure that a view has a transparent background, set the following in your XML code for that view:如果要确保视图具有透明背景,请在 XML 代码中为该视图设置以下内容:

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

This should ensure the background is completely transparent.这应该确保背景完全透明。

The code line in the ImageView or ImageButton in the XML file is actually: XML文件中ImageView或ImageButton中的代码行实际上是:

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.我写这篇文章是为了帮助不熟悉该平台并且不会连接上述两个答案的人。

I found this happens if you have android:src="@drawable/mypngimage" in your xml file.我发现如果您的 xml 文件中有android:src="@drawable/mypngimage"就会发生这种情况。 Instead if you use background then the gray area goes away and it behaves as expected.相反,如果您使用背景,则灰色区域会消失,并且会按预期运行。 android:background="@drawable/mypngimage"

Please check whether your image is 32 bit depth or not.请检查您的图像是否为 32 位深度。 After that insert this code in your image view: android:background="@android:color/transparent" .之后在您的图像视图中插入此代码: android:background="@android:color/transparent" To make your image transparent open Adobe Photoshop or Illustrator, open file (ie your image) and click file and click to export - save as web (legacy), tick transparent and save it.要使您的图像透明打开 Adobe Photoshop 或 Illustrator,打开文件(即您的图像)并单击文件并单击以导出 - 另存为 web(旧版),勾选透明并保存。

Also you can use #50FFFFFF (aarrggbb).您也可以使用#50FFFFFF (aarrggbb)。 in this format, aa is alpha channel to be transparency frequency.在这种格式中,aa 是透明频率的 alpha 通道。 So If you use above color, you get a 50% transparent white background.所以如果你使用上面的颜色,你会得到一个 50% 透明的白色背景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM