如何在android中设置包含背景颜色

Mr.*_*Mr. 7 android android-layout

如何include在Android中的标签上设置背景颜色?这不起作用:

 <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%"/>
Run Code Online (Sandbox Code Playgroud)

Sev*_*yuk 9

如果你不是"太深视树偏执"类型的球员,你可以包装您includeFrameLayout:

<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>
Run Code Online (Sandbox Code Playgroud)

编辑:当然,不要忘记android:background先从你的preference_category.xml布局中删除.


dha*_*ram 8

您无法为include标记添加背景颜色 .

为什么?

很明显,如果你能够给背景颜色include标记,那么它将全部搞砸了你的include颜色和另一种可能应用于layout已经包含的颜色.

  • 好的,但是为什么`layout_width:match_parent`有效?难道不应该有冲突吗? (15认同)
  • 对不起,看不明白。您能解释一下颜色怎么弄乱吗?顶部的颜色应该在“顶部”可见,并且如果顶部的颜色具有alpha值,则应将其与背景色混合。没有? (2认同)
  • 这似乎是一个编造的原因,其他标签如 id、尺寸被覆盖 (2认同)