gpt4 book ai didi

android - 根据主题更改布局背景

转载 作者:行者123 更新时间:2023-11-29 21:41:33 28 4
gpt4 key购买 nike

我正在尝试根据当前主题设置 View 的背景样式( Ant 文本颜色)。

在我的属性中我有:

<attr name="DirectoryRowTrackName" format="color|reference" />
<attr name="DirectoryRowSmallName" format="color|reference" />
<attr name="DirectoryRowBackground" format="color|reference" />

在我的 ActionBarSherlock 派生主题中,我有:

<style name="Theme.Xenolight" parent="@style/Theme.Sherlock.Light">
<item name="actionBarItemBackground">@drawable/selectable_background_xenolight</item>
<item name="popupMenuStyle">@style/PopupMenu.Xenolight</item>
<item name="dropDownListViewStyle">@style/DropDownListView.Xenolight</item>
<item name="actionBarTabStyle">@style/ActionBarTabStyle.Xenolight</item>
<item name="actionDropDownStyle">@style/DropDownNav.Xenolight</item>
<item name="actionBarStyle">@style/ActionBar.Solid.Xenolight</item>
<item name="actionModeBackground">@drawable/cab_background_top_xenolight</item>
<item name="actionModeSplitBackground">@drawable/cab_background_bottom_xenolight</item>
<item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Xenolight</item>

<item name="DirectoryRowTrackName">#000000</item>
<item name="DirectoryRowSmallName">#aaaaaa</item>
<item name="DirectoryRowBackground">#55ffffff</item>

</style>

然后,尝试应用颜色:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?attrs/DirectoryRowBackground"
android:id="@+id/cale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="bottom" >

结果是“无法找到当前主题的主题资源 DirectoryRowBackground”,无论我是否将其作为:

android:background="?attrs/DirectoryRowBackground"

android:background="?DirectoryRowBackground"

我做错了什么?

最佳答案

您的 RelativeLayout 中有错字。它应该是 attr 而不是 attrs

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?attr/DirectoryRowBackground"
android:id="@+id/cale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="bottom" >

关于android - 根据主题更改布局背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16936911/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com