Detailed formatting of custom attributes in Android

Source: Internet
Author: User
<span id="Label3"></p><p><p>A total of 10 custom attribute formats;</p></p><p><p>1. reference: refer to a resource ID.</p></p><p><p>2. Color: colour Value.</p></p><p><p>3. Boolean: Boolean Value.</p></p><p><p>4. Dimension: Dimension Value.</p></p><p><p>5. Float: Floating-point Value.</p></p><p><p>6. Integer: Integer Value.</p></p><p><p>7. String: Strings.</p></p><p><p>8. Fraction: Percentage.</p></p><p><p>9. Enum: Enumeration Value.</p></p><p><p>Flag: bit or Operation.</p></p><p><p></p></p><p><p>1. reference: refer to a resource ID.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><p><p></p></p><pre><pre> <declare-styleable name = "name" > <attr name = "background" format = "reference"/> </ Declare-styleable></pre></pre><p><p></p></p><p><p>(2) attribute Use:</p></p><p><p></p></p><pre><pre> <<span style="color: #000000;">ImageView </span>= "42dip"<span style="color: #000000;"> </span>= "42dip"<span style="color: #000000;"> </span>= "@drawable/picture id" /></pre></pre><p><p></p></p><p><p>2. Color: colour Value.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><pre><pre> <declare-styleable name = "name" > <attr name = "textcolor" format = "color"/> </declare-styleable ></pre></pre><p><p></p></p><br><p><p>(2) attribute Use:</p></p><pre><pre><<span style="color: #000000;"></span>= "42dip"<span style="color: #000000;"></span>= "42dip"<span style="color: #000000;"></span>= "#00FF00"/></pre></pre><p><p>3. Boolean: Boolean Value.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><pre><pre> <declare-styleable name = "name" > <attr name = "focusable" format = "boolean"/> </ Declare-styleable></pre></pre><p><p>(2) attribute Use:</p></p><p><p></p></p><p><p></p></p><pre><pre><<span style="color: #000000;">button </span>= "42dip"<span style="color: #000000;"> </span>= "42dip"<span style="color: #000000;"> </span>= "true" /></pre></pre><p><p></p></p><p><p></p></p><p><p>4. Dimension: Dimension Value.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><p><p></p></p><p><p></p></p><pre><pre> <declare-styleable name = "name" > <attr name = "layout_width" format = "dimension"/> </ Declare-styleable></pre></pre><p><p></p></p><p><p></p></p><p><p>(2) attribute Use:</p></p><pre><pre><<span style="color: #000000;"></span>= "42dip" <br> Android:layout_height = "42dip" /></pre></pre><p><p>5. Float: Floating-point Value.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><p><p></p></p><p><p></p></p><pre><pre><declare-styleable name = "alphaanimation" > <attr name = "fromalpha" format = "float"/> <br><attr name = "toalpha" format = "float"/> <br></declare-styleable></pre></pre><p><p></p></p><p><p></p></p><p><p>(2) attribute Use:</p></p><p><p></p></p><p><p></p></p><pre><pre> <<span style="color: #000000;">alpha </span>= "1.0"<br> Android:toalpha = "0.7" <br>/></pre></pre><p><p></p></p><p><p></p></p><p><p>6. Integer: Integer Value.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><p><p></p></p><p><p></p></p><pre><pre><declare-styleable name = "animatedrotatedrawable" > <attr name = "visible"/><br><attr name = "frameduration" format= "integer"/> <br><attr name = "framescount" format= "integer"/> <br><attr name = "pivotx"/> <br><attr name = "pivoty"/> <br><attr name = "drawable"/> <br></declare-styleable></pre></pre><p><p></p></p><p><p></p></p><p><p>(2) attribute Use:</p></p><p><p></p></p><pre><pre> <animated-<span style="color: #000000;">rotate </span>= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"> </span>= "@drawable/picture id" = "50%"<span style="color: #000000;"> </span>= "50%"<span style="color: #000000;"> </span>= "12" <span style="color: #000000;"> </span> <br> Android:frameduration = "/>" </pre></pre><p><p></p></p><p><p></p></p><p><p>7. String: Strings.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><p><p></p></p><p><p></p></p><pre><pre><declare-styleable name = "mapview" ><attr name = "apiKey" format = "string"/> <br></declare-styleable></pre></pre><p><p></p></p><p><p><span style="color: #00ff00;"><span style="color: #ff0000;"></span></span></p></p><p><p></p></p><p><p>(2) attribute Use:</p></p><p><p></p></p><p><p></p></p><pre><pre><<span style="color: #000000;">com.google.android.maps.MapView </span>= "fill_parent"<span style="color: #000000;"> </span>= "fill_parent"<span style="color: #000000;"> </span>= " 0jokq80od1jl9c6haja99ugxcris2cgjko_bc_g "/></pre></pre><p><p></p></p><p><p></p></p><p><p>8. Fraction: Percentage.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><p><p></p></p><p><p></p></p><pre><pre><declare-styleable name= "rotatedrawable" > <attr name = "visible"/> <attr name = "fromdegrees" format = "FL Oat "/><attr name =" todegrees "format =" float "/><attr name =" pivotx "format =" fraction "/> <br><attr name = "pivoty" format = "fraction"/> <br><attr name = "drawable"/> <br></declare-styleable></pre></pre><p><p></p></p><p><p><span style="color: #ff00ff;"><span style="color: #0000ff;"><span style="color: #ff00ff;"><span style="color: #0000ff;"></span></span></span></span></p></p><p><p></p></p><p><p>(2) attribute Use:</p></p><p><p></p></p><p><p></p></p><pre><pre><<span style="color: #000000;"></span>= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"></span>= "@anim/animation id"<span style="color: #000000;"></span>= "0"<span style="color: #000000;"></span>= "360" <span style="color: #000000;"></span> = "200%"<span style="color: #000000;"></span>= "300%" <br>Android:duration = "restart"<span style="color: #000000;"></span>= "the"<span style="color: #000000;"></span></pre></pre><p><p></p></p><p><p></p></p><p><p>9. Enum: Enumeration Value.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><p><p></p></p><p><p></p></p><pre><pre><declare-styleable name= "name" ><attr name= "orientation" > <br><<span style="color: #0000ff;">enum</span> name= "horizontal" value= "0"/> <br><<span style="color: #0000ff;">enum</span> name= "vertical" value= "1"/> <br></attr> </declare-styleable></pre></pre><p><p></p></p><p><p></p></p><p><p>(2) attribute Use:</p></p><p><p></p></p><p><p></p></p><pre><pre><<span style="color: #000000;"></span>= "http://schemas.android.com/apk/res/android"<span style="color: #000000;"></span>= "vertical" <br>Android:layout_width = "fill_parent" <br>Android:layout_height = "fill_parent" > <br></LinearLayout></pre></pre><p><p></p></p><p><p></p></p><p><p>Flag: bit or Operation.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><p><p></p></p><p><p></p></p><pre><pre> <declare-styleable name= "name" > <attr name= "windowsoftinputmode" > <br> <flag Name = "stateunspecified" Value = "0"/> <br> <flag name = "stateunchanged" Value = "1"/& Gt <br> <flag name = "statehidden" value = "2"/> <br> <flag name = "statealwayshidden" val UE = "3"/> <br> <flag name = "statevisible" Value = "4"/> <br> <flag name = "statealwaysvisible" value = "5"/> <br> <flag name = "adjustunspecifi Ed "value =" 0x00 "/> <br> <flag name =" adjustresize "value =" 0x10 "/> <br> <flag name = "adjustpan" value = "0x20"/> <br> <flag name = "adjustno Thing "value =" 0x30 "/> <br> </attr> </declare-styleable> </pre></pre><p><p></p></p><p><p></p></p><p><p>(2) attribute Use:</p></p><p><p></p></p><p><p></p></p><pre><pre><<span style="color: #000000;"></span>= ". Styleandthemeactivity "<span style="color: #000000;"> <br></span>= "@string/app_name"<span style="color: #000000;"></span>= "stateunspecified | stateunchanged | Statehidden "> <br><intent-filter> <br><action Android:name = "android.intent.action.MAIN"/> <br><category Android:name = "android.intent.category.LAUNCHER"/> <br></intent-filter> <br></activity></pre></pre><p><p></p></p><p><p></p></p><p><p><span style="color: #ff0000;">note:</span></p></p><p><p></p></p><p><p>Multiple types of values can be specified when the property is Defined.</p></p><p><p></p></p><p><p>(1) attribute Definition:</p></p><p><p></p></p><p><p></p></p><pre><pre><declare-styleable name = "name" ><attr name = "background" format = "reference|color"/></declare-styleable ></pre></pre><p><p></p></p><p><p></p></p><p><p>(2) attribute Use:</p></p><p><p></p></p><p><p></p></p><pre><pre><<span style="color: #000000;"></span>= "42dip"<span style="color: #000000;"></span>= "42dip"<span style="color: #000000;"></span>= "@drawable/picture id| #00FF00"/></pre></pre><p><p></p></p><p><p>Detailed formatting of custom attributes in Android</p></p></span>

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.