ATTR attribute settings

Source: Internet
Author: User

 

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.