Android查看背景: How to specify background color for PNG transparency?

标签 android android-layout background android-linearlayout transparent

我希望 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 drawablesoverlay 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/

相关文章:

android - 丢失了 keystore 的密码

java - 使用EMM限制AirWatch在PlayStore上发布应用程序时收到错误

Android:ListView 在其他元素之上

Android GridView 选中项背景

css - Jquery Mobile - 设置文本框背景

javascript - Android 中使用 PhoneGap 的离线事件

android - 尝试将多个复选框添加到 Android Studio 上的数组中

java - 如何将一堆线性布局转换为一个相对布局

java - android中的时间范围搜索栏

firebase - 在 Flutter 上单击背景通知时如何导航?