Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当父布局有另一种背景色时,如何为子布局设置默认的android黑色?_Android_Android Layout_Background Color - Fatal编程技术网

当父布局有另一种背景色时,如何为子布局设置默认的android黑色?

当父布局有另一种背景色时,如何为子布局设置默认的android黑色?,android,android-layout,background-color,Android,Android Layout,Background Color,我在父布局中有一个子布局。如果我为父对象设置任何背景色,它也会为其子对象设置相同的颜色。但我不想给孩子设置相同的颜色。(我想要默认的android黑色作为孩子的背景)。请帮帮我。 编辑: 我需要捕获子布局并稍后创建位图,因此我不应该为子布局设置任何背景颜色(但其父布局应该有一些颜色)。它应该设置为默认的android黑色 <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_

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

<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>


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

你可以将孩子布局的背景色设置为透明

设置:

android:background=“00000000”

前两个十六进制数是背景的alpha分量

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

不,没有。默认情况下,您的子对象只有一个透明背景,因此它看起来像是从其父对象继承了颜色。只需将其设置为透明以外的其他值

编辑:

抱歉,请阅读您的编辑


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

子视图是一个视图。因此,使用您的parentview.findViewByid(R.id.yourChildId)获取它;设置背景色我已经编辑了我的问题。我不想让子布局有任何背景,而其父布局有一些颜色。我不明白你想做什么,如果我为子布局设置android:background=“#00000000”,它也为子布局显示相同的背景颜色。(但当我捕获子布局时,它不会使用任何BG颜色)是否有任何方法阻止子布局从其父布局输入BG颜色?捕获子布局后,您始终可以通过编程方式更改layaout的背景颜色!如果我捕获子布局(带有一些BG颜色)并创建位图,是否可以删除位图的BG颜色?