Description of ATTR. XML in the values file: Requirements for the attribute format
<Declare-styleable name = "favorite"> <br/> <ATTR name = "classname" format = "string"/> <br/> <ATTR name = "packagename" Format = "string"/> <br/> <ATTR name = "screen" format = "string"/> <br/> <ATTR name = "X" format = "string" /> <br/> <ATTR name = "Y" format = "string"/> <br/> </declare-styleable>
Declare your own attributes: <declare-styleable name = "favorite"> ---> define your own style name
<ATTR name = "animationduration" format = "integer"/>
Define attributes in your own style, such as animationduration ---> format requirements
For example, I add Judy. XML to the XML folder.
The specific content of XML is as follows:
<Favorites xmlns: Judy = "http://schemas.android.com/apk/res/com.android.launcher"> <br/> <favorite <br/> JUDY: packagename = "com. android. vending "<br/> JUDY: classname =" com. android. vending. assetbrowseractivity "<br/> JUDY: screen =" 1 "<br/> JUDY: x =" 3 "<br/> JUDY: y = "2"/> <br/> <favorites/>
You can also define attributes through ATTR and then reference them in XML. Add
Note: xmlns: Judy = "http://schemas.android.com/apk/res/your package name ---> defined at home
Xmlns: Android = "http://schemas.android.com/apk/res/android ---> reference properties under the namespace of the android System
In this way, the attributes defined in ATTR can be used in the Judy space in XML of layout.
Typedarray A = context. obtainstyledattributes (attrs, R. styleable. panel); <br/> mduration =. getinteger (R. styleable. panel_animationduration, 750); // duration defaults to 750 ms <br/> mposition =. getinteger (R. styleable. panel_position, bottom); // position defaults to bottom <br/> mlinearflying =. getboolean (R. styleable. panel_linearflying, false); // linearflying defaults to false <br/> mopenedhandle =. getdrawable (R. styleable. panel_openedhandle); <br/> mclosedhandle =. getdrawable (R. styleable. panel_closedhandle); <br/>. recycle ();
When attributes defined in ATTR are applied in the class, the attributes defined in ATTR are obtained through typedarray A = obtainstyledattributes (attrs, R. styleable. Panel ); //
Then obtain the corresponding attributes, such
Mduration = A. getinteger (R. styleable. panel_animationduration, 750); // duration defaults to 750 MS
Because the animationduration defined in ATTR is in integer format. You can assign a value of 750 to all of them ..
Generally, such statements are initialized ..
A. Recycle (); // make the initialization take effect.