Reputation: 287
In my attr.xml
, I have defined descriptor_bg
like:
</declare-styleable>
<attr name="descriptor_bg" format="reference|color" />
</declare-styleable>
and in style.xml
:
<style name="Theme_blue">
<item name="descriptor_bg">@android:color/black</item>
<item name="android:windowNoTitle">true</item>
</style>
I have used above attribute like:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90" />
<solid android:color="@attr/descriptor_bg"/>
<stroke
android:width="2dp"
android:color="@color/blue_stroke_bg" />
But I am getting an exception like:
android.content.res.Resources$NotFoundException: File res/drawable-mdpi/descriptor_bg.xml
from drawable resource ID #0x7f020006
java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
File res/drawable-mdpi/descriptor_bg.xml from drawable resource ID #0x7f020006
Can anyone please help me?
Upvotes: 1
Views: 1429
Reputation: 2369
I think the correct syntax is ?attr/descriptor_bg.
Unfortunately this probably won't fix your issue, because theme attributes aren't supported in XML drawables. This was fixed in L-preview release though.
Upvotes: 1
Reputation: 68187
I guess you need to stick to a single format identifier, like:
<attr name="descriptor_bg" format="color" />
It should automatically translate the color from RGB value or reference.
Upvotes: 0