我正在尝试根据当前主题设置视图的背景(蚂蚁文本颜色)。
在我的阁楼里,我有:<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"
我做错了什么?
答案 0 :(得分:2)
您的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" >