我希望 Android View 的背景是白色背景上的 Logo 。
我可以将 View 的背景设为白色:
android:background="@color/colorWhite"
我可以将 View 的背景设置为 PNG:
android:background="@drawable/logo"
但不能同时两者 ( Attribute "android:background" was already specified
)。
如果我只写@drawable/logo
然后将 Logo 绘制在黑色背景上。
怎么做?最好不添加 View 层。
解决方案:我使用了 Avinazz 的第一个建议,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@color/white"/>
<item>
<bitmap android:src="@drawable/logo"
android:gravity="center" />
</item>
</layer-list>
与 strings.xml
包含<color name="white">#FFFFFF</color>
.
最佳答案
几种可能性:
1) 使用Layer drawables或overlay two images in android to set an imageview
2) 调整您的 xml,使容器背景具有白色背景,并让子项具有您想要的具有透明度的图像。
3)编辑图像以具有白色背景。
关于Android查看背景: How to specify background color for PNG transparency?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14557197/