小编Ahm*_*met的帖子

使用属性修改可绘制元素颜色

我尝试Drawable使用属性进行自定义但我有一个膨胀错误

01-21 11:01:06.171: E/AndroidRuntime(13695): Caused by: android.content.res.Resources$NotFoundException: 
File res/drawable/action_bar_background.xml from drawable resource ID #0x7f020000
Run Code Online (Sandbox Code Playgroud)

我的action_bar_background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
 android:shape="rectangle" >
    <gradient
        android:angle="90"
        android:endColor="?attr/ActionBarEndColor"
        android:startColor="?attr/ActionBarStartColor" 
    />
</shape>
Run Code Online (Sandbox Code Playgroud)

我的attr.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
     <attr name="ActionBarStartColor" format="reference|color" />
     <attr name="ActionBarEndColor" format="reference|color" />
</resources>
Run Code Online (Sandbox Code Playgroud)

我的themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.Theme1" parent="@style/Theme.GreenDroid.Light.NoTitleBar">
        <item name="ActionBarStartColor">@color/greyDark</item>
        <item name="ActionBarEndColor">@color/greyLight</item>
    </style>

    <style name="Theme.Theme2" parent="@style/Theme.GreenDroid.Light.NoTitleBar">
        <item name="ActionBarStartColor">@color/myRed</item>
        <item name="ActionBarEndColor">@color/myWhite</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

我不明白为什么,我的属性是引用或颜色,如果我"强制"在themes.xml中的颜色,它也不起作用.

有人可以帮忙吗?

我发现了这个问题,但它并没有解决我的问题.

android themes attr

21
推荐指数
1
解决办法
5919
查看次数

标签 统计

android ×1

attr ×1

themes ×1