Android - UnsupportedOperationException: Cant convert to color: type=0x2

 You are most likely trying to reference a styleable attribute of reference type in a drawable resource and it bailed out with an UnsupportedOperationException.

   <shape android:shape="rectangle">
        <solid android:color="?attr/item_background" />
    </shape>

Sadly this is the case with pre-lollipop android versions. There isn't any way to reference attributes in a drawable resource. This works just fine in Lollipop though and is tracked here. The only other alternative is to have a hard coded color specific drawable resource for older platform versions.

/drawable/red_rectangle.xml

   <shape android:shape="rectangle">
        <solid android:color="@android:color/red" />
    </shape>

/drawable/orange_rectangle.xml

   <shape android:shape="rectangle">
        <solid android:color="@android:color/orange" />
   </shape>

1 comment:

Flagstar Rehab said...

Thank you, Nice information shared, I appreciated your work Thank you.
Visit here:- OT staffing company in New York