Format attribute value "android:drawable" not valid

Viewed 55102

I'm trying to create custom attributes to my button but I dont know which format I must use to images in attributes declaration...

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <declare-styleable name="TCButton">
        <attr name="Text" format="string"/>
        <attr name="BackgroundImage" format="android:drawable"  />
    </declare-styleable>


</resources>

Error is in the format="android:drawable"...

3 Answers

From AOSP code, I found how google engineers declare ImageView#src attr.

<declare-styleable name="ImageView">
    <attr name="src" format="reference|color" />
    <attr name="scaleType">
        <enum name="matrix" value="0" />
        <enum name="fitXY" value="1" />
        <enum name="fitStart" value="2" />
        <enum name="fitCenter" value="3" />
        <enum name="fitEnd" value="4" />
        <enum name="center" value="5" />
        <enum name="centerCrop" value="6" />
        <enum name="centerInside" value="7" />
    </attr>
    <attr name="adjustViewBounds" format="boolean" />
    <attr name="maxWidth" format="dimension" />
    <attr name="maxHeight" format="dimension" />
    <attr name="tint" format="color" />
    <attr name="baselineAlignBottom" format="boolean" />
    <attr name="cropToPadding" format="boolean" />
    <attr name="baseline" format="dimension" />
    <attr name="drawableAlpha" format="integer" />
    <attr name="tintMode" />
</declare-styleable>

Above code is a sample and it can cover most case in our development.

Related