Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android custom widget styles: how to put them into a namespace?

Tags:

android

widget

In the ApiDemos, there is a view example called Gallery1 which declares a custom style in attrs.xml, as such:

<declare-styleable name="Gallery1">
    <attr name="android:galleryItemBackground" />
</declare-styleable>

now, I want to do the same thing for my widgets, but using a different namespace. However, as soon as I replace the android: namespace with something else, I get this error:

ERROR: In Gallery1, unable to find attribute myns:galleryItemBackground

Unable to find attribute? Why does it look for an attribute I am about to declare? Isn't the point of this file to be able to name your own custom attributes?

It's interesting to note that it works if you do not supply a custom namespace, but just an attribute name.

like image 287
Matthias Avatar asked Sep 21 '09 07:09

Matthias


1 Answers

I had a similar problem resulting in the error message No resource identifier found for attribute in package

The solution for me was to declare the namespace when you use the custom attribute.

In your xml file where you use your custom attribute specify:

xmlns:myns="http://schemas.android.com/apk/res-auto"

...

<gallery.widget.package.Gallery1


myns:myCustomAttr="xxx"
/>
like image 100
thumbmunkeys Avatar answered Sep 18 '22 17:09

thumbmunkeys