Usually al examples of custom attributes are of the form:
<declare-stylable name="MyView">
<attr name="name" format="string"/>
</declare-styleable>
and its usage:
<com.example.test.MyView
customns:name="Hello"/>
So the custom view has the same name as the stylable attributes.
But in this example (click for full code) you see:
<declare-styleable name="Options">
<attr name="titleText" format="string" localization="suggested" />
<attr name="valueColor" format="color" />
</declare-styleable>
used by:
<com.vogella.android.view.compoundview.ColorOptionsView
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
custom:titleText="Background color"
custom:valueColor="@android:color/holo_green_light"
/>
It made me wonder, how is it that ColorOptionsView was linked to the attributes defined with name Options?
Those options are available as part of the declared
namespacecustom, which is included at the top of theXMLfile:NOTE
Simply adding this line will not provide support for auto-complete. If that is what your mean by your question, you need to add the schema to your workspace's XML Catalog. You can do this in Eclipse by going to
Eclipse -> Preferences, thenXML -> XML Catalog. Here, click theAdd...button. Navigate to the XML Schema file, then selectOK. If you close and re-open the the XML file, you will now have autocompletion.Finally, when unpacking the attributes used in
ColorOptionsView.java, the author can specifically look for attributes from this namespace. This is from the same source (commented by me):