问题描述
我想使用在选择一个stlyle定义的颜色,但它造成了资源$ NotFoundException。
首先,我添加了一个新属性attr.xml:
<资源>
< attr指示NAME =unread_background格式=颜色/>
< /资源>
然后,我在styles.xml定义attr属性值:
<样式名称=ThemeNoTitleBar父=机器人:Theme.NoTitleBar>
<项目名称=unread_background>#000000< /项目>
< /风格>
然后我试图用attr属性在我选择的定义:
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android>
<! - 其他国家剪断 - >
<项目安卓state_selected =假
机器人:unread_background绘制= />
< /选择器>
最后,活动使用的ThemeNoTitleBar风格主题清单。
我也试着创造colors.xml一种颜色,让它使用新ATTR但也失败。
我显然失去了一些东西,但我不知道该怎么做才能解决这个问题。我的目的是创建多个主题,并有选择器使用的颜色在当前选择的主题。
<项目安卓state_selected =假
机器人:unread_background绘制= />
这上面的部分是错误的。
可绘制只需要参照绘制资源。请参阅此链接。的
I'm trying to use a color defined in a stlyle in a selector but it is causing a Resources$NotFoundException.
First I added a new attribute to attr.xml:
<resources>
<attr name="unread_background" format="color" />
</resources>
Then I defined that attr value in styles.xml:
<style name="ThemeNoTitleBar" parent="android:Theme.NoTitleBar">
<item name="unread_background">#000000</item>
</style>
Then I tried to use that attr in my selector definition:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- other states snipped -->
<item android:state_selected="false"
android:drawable="?unread_background" />
</selector>
Lastly, the activity uses the ThemeNoTitleBar style theme in the manifest.
I've also tried creating a color in colors.xml and having it use the new attr but that also fails.
I'm obviously missing something but am not sure what to do to fix it. My intent is to create multiple themes and have the selector use the color in the currently selected theme.
<item android:state_selected="false"
android:drawable="?unread_background" />
this above section is wrong.
the drawable only take a reference to a drawable resource. Please see this link. http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
这篇关于可以在选择资源使用的样式定义的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!