0

我在其父布局中有一个子布局。如果我为父级设置任何背景颜色,它也会为其子级设置相同的颜色。但我不想为孩子设置相同的颜色。(我想要默认的android黑色作为孩子的背景)。请帮我。
编辑:
我需要捕获子布局并稍后创建位图,所以我不应该为子设置任何背景颜色(但它的父级应该有一些颜色)。它应该只设置为默认的 android black。

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="#FFA500" >

    <RelativeLayout

        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_margin="15dp"
        android:layout_weight="1"
        android:gravity="center" >
    </RelativeLayout>
</LinearLayout>

父线性布局有一些 BG 颜色。我没有为子相对布局设置任何 BG 颜色,但它采用了父的 BG 颜色。那么现在,我该如何为孩子设置 android 默认 BG 颜色?

4

2 回答 2

0

您可以将子布局的背景颜色设置为透明。

放:

android:background="00000000";

前 2 个十六进制数字是背景的 alpha 分量。

于 2012-05-23T11:24:16.060 回答
0

如果我为父级设置任何背景颜色,它也会为其子级设置相同的颜色

不,它没有。默认情况下,您的孩子只有透明背景,因此看起来它是从其父级继承颜色。只需将其设置为透明以外的其他内容。

编辑:

抱歉,请阅读您的编辑。

如果您想稍后将图像添加到您的子视图,而不是设置setBackgroundDrawable或其他东西,请使用setImageBitmap. 它将保留您的子视图的透明颜色,同时显示您指定的图像。

于 2012-05-23T11:31:30.593 回答