Get resource ID (R.string.name) of string value from Android attr in custom view

959 Views Asked by At

My application has a custom view, styled by attrs.xml entry:

<resources>
    <declare-styleable name="MyView">
        <attr name="title" format="reference" />
        <attr name="image" format="reference" />
    </declare-styleable>
</resources>

In my custom view, I need to retreive the resource ID of resource specified as title in attrs.xml, but I can only retreive the content of string specified as title. Fo far, I've tried using:

attrs.getAttributeResourceValue(R.styleable.MyView_title, 0)

And

getSourceResourceId(R.styleable.MyView_title, 0)

But in both cases, the returned value is the default 0.

I've tries the same approach with other types of attributes, and for example, Drawable ID can be easilly retrieved by:

getResourceId(R.styleable.MyView_image, 0)

Is there any way to check what R.string was provided in XML?

0

There are 0 best solutions below