"Reprint" Android attr custom tags in detail

Source: Internet
Author: User

Original link: http://blog.sina.com.cn/s/blog_62ef2f14010105vi.html; only the layout is optimized for easier reading

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:wen=http://schemas.android.com/apk/res/com.iteye.googlers
android:orientation= "vertical" android:layout_width= "fill_parent"
android:layout_height= "Wrap_content" >

The second line is a custom label.

Format as above, where the "Xmlns:wen" Colon is followed by a label name, when used below (only available for the current file)

<textview Wen: Property name/>

"Com.iteye.googlers" is the name of your project package.

1. Reference: Refer to a resource ID.

(1) Attribute definition:
<declare-styleable name = "Names" >
<attr name = "Background" format = "Reference"/>
</declare-styleable>
(2) attribute use:
<imageview
Android:layout_width = "42dip"
Android:layout_height = "42dip"
Android:background = "@drawable/Picture ID"
/>

2. Color: Colour value.

(1) Attribute definition:
<declare-styleable name = "Names" >
<attr name = "TextColor" format = "Color"/>
</declare-styleable>
(2) attribute use:
<textview
Android:layout_width = "42dip"
Android:layout_height = "42dip"
Android:textcolor = "#00FF00"
/>

3. Boolean: Boolean value.

(1) Attribute definition:
<declare-styleable name = "Names" >
<attr name = "focusable" format = "Boolean"/>
</declare-styleable>
(2) attribute use:
<button
Android:layout_width = "42dip"
Android:layout_height = "42dip"
Android:focusable = "true"
/>


4. Dimension: Dimension value.

(1) Attribute definition:
<declare-styleable name = "Names" >
<attr name = "layout_width" format = "Dimension"/>
</declare-styleable>
(2) attribute use:
<button
Android:layout_width = "42dip"
Android:layout_height = "42dip"
/>

5. Float: floating-point value.

(1) Attribute definition:
<declare-styleable name = "Alphaanimation" >
<attr name = "Fromalpha" format = "float"/>
<attr name = "Toalpha" format = "float"/>
</declare-styleable>
(2) attribute use:
<alpha
Android:fromalpha = "1.0"
Android:toalpha = "0.7"
/>

6. Integer: Integer value.

(1) Attribute definition:
<declare-styleable name = "Animatedrotatedrawable" >
<attr name = "visible"/>
<attr name = "frameduration" format= "integer"/>
<attr name = "Framescount" format= "integer"/>
<attr name = "Pivotx"/>
<attr name = "Pivoty"/>
<attr name = "Drawable"/>
</declare-styleable>
(2) attribute use:
<animated-rotate
xmlns:android = "Http://schemas.android.com/apk/res/android"
android:drawable = "@drawable/Picture ID"
Android:pivotx = "50%"
Android:pivoty = "50%"
Android:framescount = "12"
android:frameduration = "100"
/>


7. String: Strings.


(1) Attribute definition:
<declare-styleable name = "Mapview" >
<attr name = "ApiKey" format = "string"/>
</declare-styleable>
(2) attribute use:
<com.google.android.maps.mapview
Android:layout_width = "Fill_parent"
Android:layout_height = "Fill_parent"
Android:apikey = "0jokq80od1jl9c6haja99ugxcris2cgjko_bc_g"
/>

8. Fraction: percentage.


(1) Attribute definition:
<declare-styleable name= "Rotatedrawable" >
<attr name = "visible"/>
<attr name = "fromdegrees" format = "float"/>
<attr name = "todegrees" format = "float"/>
<attr name = "Pivotx" format = "fraction"/>
<attr name = "Pivoty" format = "fraction"/>
<attr name = "Drawable"/>
</declare-styleable>

(2) attribute use:
<rotate
xmlns:android = "Http://schemas.android.com/apk/res/android"
Android:interpolator = "@anim/animation ID"
Android:fromdegrees = "0"
Android:todegrees = "360"
Android:pivotx = "200%"
Android:pivoty = "300%"
android:duration = "5000"
Android:repeatmode = "Restart"
Android:repeatcount = "Infinite"
/>

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 use:
<linearlayout
xmlns:android = "Http://schemas.android.com/apk/res/android"
Android:orientation = "vertical"
Android:layout_width = "Fill_parent"
Android:layout_height = "Fill_parent"
>
</LinearLayout>

Flag: Bit or operation.


(1) attribute definition:
<declare-styleable name= "name";
<attr name= "Windowsoftinputmode";
<flag Name = "Stateunspecified" value = "0"/>
<flag name = "stateunchanged" value = "1"/>
<flag name = "St Atehidden "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"/&G T
<flag name = "adjustnothing" value = "0x30"/>
</attr>
</declare-styleable>

(2) attribute use:
<activity
Android:name = ". Styleandthemeactivity "
Android:label = "@string/app_name"
Android:windowsoftinputmode = "Stateunspecified | stateunchanged | Statehidden ">
<intent-filter>
<action android:name = "Android.intent.action.MAIN"/>
<category android:name = "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

Tips: You can specify multiple types of values when you define a property.

(1) Attribute definition:
<declare-styleable name = "Names" >
<attr name = "Background" format = "Reference|color"/>
</declare-styleable>
(2) attribute use:
<imageview
Android:layout_width = "42dip"
Android:layout_height = "42dip"
Android:background = "@drawable/Picture id| #00FF00"
/>

"Reprint" Android attr custom tags in detail

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.