【问题标题】:android background in xml: tranparency become black not whitexml中的android背景:透明度变成黑色而不是白色
【发布时间】:2013-12-09 15:37:16
【问题描述】:

我为android界面制作了一个xml文件。在这个 xml 中,有一个消耗品。我想用透明(alpha)为这个xml添加背景,但是当我在相对布局中添加bacground时,像这样

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:alpha="0.2"
tools:context=".ListGestureActivity" >

这将使背景透明度变为黑色而不是白色。在其他 xml 中也发生了这样的事情。 但在其他 xml 中我尝试这样做

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".HintGestureActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:alpha="0.3"
    android:background="@drawable/background"
    />

成功了。但是在带有消耗性物品的xml中不起作用。 你有什么建议吗?

【问题讨论】:

  • @drawable/background 的值是多少?
  • AndroidMenifest.xml 中,您为activity 使用的是哪个主题? Dark 还是 Light?如果是Dark,则设为Light 并尝试一下。告诉结果。
  • @drawable/bacground 是我想要作为背景的图像
  • 致 MrSuS -- 我不使用任何主题

标签: android xml background alpha-transparency


【解决方案1】:

你可以做这样的事情

android:background="#00564678"

例如:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:alpha="0.3"
    android:background="#00564678"
    />

【讨论】:

  • 我想让@drawable/background 作为我的界面背景
  • color--“#00564678”是透明色。仅使用此设置背景。
【解决方案2】:

默认情况下,它采用黑色作为背景颜色,然后,如果应用透明度,则不会获得所需的输出。因此,首先需要设置一些背景颜色,然后应用alpha。试试这个:

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:alpha="0.2"
tools:context=".ListGestureActivity" >

【讨论】:

  • 我想让@drawable/background 作为我的界面背景
  • “将@drawable/backgroud 作为您的界面”是什么意思?我没有得到你想要做的事情?
猜你喜欢
  • 1970-01-01
  • 2013-11-25
  • 1970-01-01
  • 2011-02-06
  • 2012-06-26
  • 2013-09-21
  • 1970-01-01
  • 2016-01-04
  • 2015-04-01
相关资源
最近更新 更多