XML Attribute Definition

Source: Internet
Author: User
Tags xml attribute

1. Reference: refer to a resource ID.

1) attribute definition:

<Declare-styleable name = "name">

<ATTR format = "Reference" name = "background"/>

</Declare-styleable>

 

 

2) attribute usage:

<Imageview

Android: layout_width = "42dip"

Android: layout_height = "42dip"

Android: Background = "@ drawable/image ID"/>

 

 

2. Color: color value.

(1) attribute definition:

<Declare-styleable name = "name">

<ATTR format = "color" name = "textcolor"/>

</Declare-styleable>

 

 

(2) attribute usage:

<Textview

Android: layout_width = "42dip"

Android: layout_height = "42dip"

Android: textcolor = "#00ff00"/>

 

 

3. boolean: Boolean value.

(1) attribute definition:

<Declare-styleable name = "name">

<ATTR format = "Boolean" name = "focusable"/>

</Declare-styleable>

 

 

(2) attribute usage:

<Button

Android: layout_width = "42dip"

Android: layout_height = "42dip"

Android: focusable = "true"/>

 

 

4. dimension: dimension value.

(1) attribute definition:

<Declare-styleable name = "name">

<ATTR format = "dimension" name = "layout_width"/>

</Declare-styleable>

 

 

(2) attribute usage:

<Button

Android: layout_width = "42dip"

Android: layout_height = "42dip"/>

 

 

5. Float: floating point value.

(1) attribute definition:

<Declare-styleable name = "alphaanimation">

<ATTR format = "float" name = "fromalpha"/>

<ATTR format = "float" name = "toalpha"/>

</Declare-styleable>

 

 

(2) attribute usage:

<Alpha

Android: fromalphi = "1.0"

Android: toalpha = "0.7"/>

 

 

6. Integer: integer value.

(1) attribute definition:

<Declare-styleable name = "animatedrotatedrawable">

<ATTR format = "integer" name = "frameduration"/>

<ATTR format = "integer" name = "framescount"/>

</Declare-styleable>

 

 

(2) attribute usage:

<Animated-Rotate

Android: frameduration = "100"

Android: framescount = "12"

/>

 

 

7. String: string.

(1) attribute definition:

<Declare-styleable name = "mapview">

<ATTR format = "string" name = "apikey"/>

</Declare-styleable>

 

 

(2) attribute usage:

<Com. Google. Android. Maps. mapview

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

Android: apikey = "0jokq80od1jl9c6haja99ugxcri2cgjko_bc_g"/>

 

 

8. fraction: percentage.

(1) attribute definition:

<Declare-styleable name = "rotatedrawable">

<ATTR format = "fraction" name = "Hangzhou TX"/>

<ATTR format = "fraction" name = "policty"/>

</Declare-styleable>

 

 

(2) attribute usage:

<Rotate

Android: Required Tx = "200%"

Android: Ty = "300%"

/>

 

 

9. Enum: enumeration value.

(1) attribute definition:

<Declare-styleable name = "name">

<ATTR name = "orientation">

<Enum name = "horizontal" value = "0"/>

<Enum name = "vertical" value = "1"/>

</ATTR>

</Declare-styleable>

 

 

(2) attribute usage:

<Linearlayout

Android: Orientation = "vertical">

</Linearlayout>

 

 

10. Flag: bitwise OR operation.

(1) attribute definition:

<Declare-styleable name = "name">

<ATTR name = "windowsoftinputmode">

<Flag name = "stateunspecified" value = "0"/>

<Flag name = "stateunchanged" value = "1"/>

<Flag name = "statehidden" value = "2"/>

<Flag name = "statealwayshidden" value = "3"/>

<Flag name = "statevisible" value = "4"/>

<Flag name = "statealwaysvisible" value = "5"/>

<Flag name = "adjustunspecified" value = "0x00"/>

<Flag name = "adjustresize" value = "0x10"/>

<Flag name = "adjustpan" value = "0x20"/>

<Flag name = "adjustnothing" value = "0x30"/>

</ATTR>

</Declare-styleable>

 

 

(2) attribute usage:

<Activity

Android: windowsoftinputmode = "stateunspecified | stateunchanged | statehidden">

</Activity>

 

 

Note: multiple types of values can be specified during attribute definition:

(1) attribute definition:

<Declare-styleable name = "name">

<ATTR format = "reference | color" name = "background"/>

</Declare-styleable>

 

 

(2) attribute usage:

<Imageview

Android: layout_width = "42dip"

Android: layout_height = "42dip"

Android: Background = "@ drawable/image ID | #00ff00"/>

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.