Values create a new Attrs.xml
<resource>
<declare-styleable name = "Mytextview" >
<attr name= "title" Format= " String "/>
<attr name=" switch_on "format=" string "/
&NBSP;&NBSP;&NBSP;&NBSP;</DECLARE-STYLEABLE>
</resource>
Layout file
Custom namespace res followed by package name
xmlns:exayong= "http://schemas.android.com/apk/res/ Com.exayong.abc "
<mytextview
exayong:title=" Hello "
exayong:switch_on=" on "
/>
Mytextview.java extends Relativelayout
Construction method with properties
Attrs.getattributename (index);
//Get the custom namespace, name of the property
Attrs.getattributevalue (namespace,name);
String myTitle = Attrs.getattributevalue ("Http://schemas.android.com/apk/res/com.exayong.abc", "title");
1 Customizing a View inheritance ViewGroup
2 writing a layout file for a combined control, loading in a custom view inflate
Summarize:
The values of some properties of the own view are statically written in the layout file as a custom attribute,
Then by customizing the view inflate Findviewbyid-->view such as TextView
Get the value of a custom property by customizing the view band Attrs constructor
These values are then set to some properties of the own view, such as Textview.settext (MyTitle), through the own view method.
Android Custom Properties