Android Custom Widget Styles: How To Put Them Into A Namespace?
In the ApiDemos, there is a view example called Gallery1 which declares a custom style in attrs.xml, as such:
xmlns:myns="http://schemas.android.com/apk/res-auto"
...
<gallery.widget.package.Gallery1
myns:myCustomAttr="xxx"
/>
Solution 2:
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"/>
Solution 3:
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."
Solution 4:
create a xml file and paste this below code and put in res->values folder
<declare-styleablename="Gallery1"><attrname="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);
Post a Comment for "Android Custom Widget Styles: How To Put Them Into A Namespace?"