This tag is part of the set of Android pre-attributes defined in R.Styleable , which can be passed separately from the custom tag with the android: xml space prefix tag in front of the attribute name.
This particular attribute is described as:
Preferred background for gallery elements. This should be set as the background of any kinds that you provide from the adapter.
However, you are correct that for special attribute tags you will need not only the attribute name, but also its type, for example, adding a custom element to your
attrs.xml file may look like this:
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="MyCustomView"> <attr name="android:galleryItemBackground" /> <attr name="myCustomAttr" format="string" /> </declare-styleable> </resources>
Note the lack of the android: namespace in the second attribute.
Edit:
Is there any official documentation page that explains this in detail for Styleables?
Check out R.attr (click for a link) for the various attributes included in Android. You do not need to declare a type for them, because they are all already declared. To find out what type was declared for a particular attribute, find a description for the one you are interested in. galleryItemBackground , as you might expect, refers to another resource; other features - booleans, floats, colors, etc.
Additional links: Andtoid uses the <declare-styleable> to create an AttributeSet . TypedArray used to analyze the AttributeSet .
If the goal of the code is above [...] - just get the default value. Can I draw for the background of the view, can I set the itemBackground variable with getDrawable (android.R.attr.galleryItemBackground)?
In this example, it is difficult to understand the utility of this template when there is only one attribute. You can do what you ask, and it can be easier. The design, however, is part of the Android mantra to separate the user interface from “functionality”, allowing you to set certain attributes in xml instead of doing everything in code. Take the View class, for example. It has more than 30 attributes that can be set in an XML file (size, addition, clickability, focusability, etc.); someone creating their own subclass of View can set several, all, or none of these attributes in xml, and they are automatically processed for you when the view is created. There are code equivalents for setting attributes, if necessary, but imagine every time you subclass View , you had to set all the attributes in the code instead of setting them in xml.
It would also be a trivial matter to simply make your own resources for your classes that will do the same, however using inline styles will provide default resources that match the look and structure of Android if you don't override them.
Hope this helps.