In the ApiDemos, there is a view example called Gallery1 which declares a custom style in attrs.xml, as such:
create a xml file and paste this below code and put in res->values folder
<declare-styleable name="Gallery1">
<attr name="android:galleryItemBackground" />
</declare-styleable>
and then copy below code
TypedArray typedArray=this.obtainStyledAttributes(R.styleable.Gallery1);
int back=typedArray.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
typedArray.recycle();
and set in ur widget background i mean imageView.setBackgroundResource(back);
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"
/>
In case someone is still interested, I had the same problem and solved it by adding a 'format' attribute (it seems it doesn't take 'string' as the default):
<attr name="android:galleryItemBackground" format="integer"/>
I found this article helpful in similar situation.
"Referring to our new attributes is actually a two step process. First we declared a new namespace and next we specified the values of our new attributes in the XML usage."