如何在android中设置包含背景色
如何在Android中设置如何在android中设置包含背景色,android,android-layout,Android,Android Layout,如何在Android中设置include标签的背景色?这不起作用: <include android:id="@+id/list_item_section_text" android:layout_width="fill_parent" android:layout_height="match_parent" layout="@android:layout/preference_category" android:background="%MY_BACKGROUND%"/>
include
标签的背景色?这不起作用:
<include
android:id="@+id/list_item_section_text"
android:layout_width="fill_parent"
android:layout_height="match_parent"
layout="@android:layout/preference_category"
android:background="%MY_BACKGROUND%"/>
您不能为include
标记指定背景色
为什么?
很明显,如果你能给include
标签加上背景色,那么你的include
颜色和另一种可能应用于已经包含的布局的颜色都会弄乱
但是,您也可以通过在标记中指定包含布局的根视图的所有布局参数(任何android:layout_*属性)来覆盖它们。
(引用自)试试这个:
<include
android:id="@+id/list_item_section_text"
android:layout_width="fill_parent"
android:layout_height="match_parent"
layout="@android:layout/preference_category"/>
如果你不是“太深的树妄想症”类型的人,你可以将你的包含在框架布局中
:
<FrameLayout
android:id="@+id/list_item_section_text"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="%YOUR_BACKGROUND%">
<include layout="@android:layout/preference_category"/>
</FrameLayout>
编辑:当然,别忘了先从您的preference\u category.xml
版面中删除android:background
。对不起,我不明白明显的问题。你能解释一下这些颜色是怎么弄乱的吗?顶部的颜色应该是可见的“顶部”,如果顶部的颜色具有alpha值,则应该与背景色混合。否?简单地说,为了避免包含标记值与包含标记所包含的值之间的冲突,不允许您提供包含标记的bg颜色。好的,但是为什么layout\u width:match\u parent
?难道不应该也有冲突吗?这似乎是一个虚构的原因,其他标签,如id,维度都是overwritten@BugsHappen请参考卓越解决方案:)
preference_category.setBackgroundResource(R.id.bckResource);
<FrameLayout
android:id="@+id/list_item_section_text"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="%YOUR_BACKGROUND%">
<include layout="@android:layout/preference_category"/>
</FrameLayout>