Android中自定义属性的格式详解
来源:互联网 发布:郑州php培训 编辑:程序博客网 时间:2024/05/17 23:01
1. reference:参考某一资源ID。
(1)属性定义:
1 c: g+ L& j r) j<declare-styleable name = "名称">
<attr name = "background" format = "reference" />
</declare-styleable>
* k$ S' r- [! g: E0 ~(2)属性使用:
<ImageView
android:layout_width = "42dip"8 U; W8 T T& H0 ~* X; X
android:layout_height = "42dip"9 \$ M" X; M& z- \: I$ |2 x+ v
android:background = "@drawable/图片ID"
/>
; g/ n" P, K) Y& M3 F2. color:颜色值。
(1)属性定义:
8 F ~; \" s8 X3 K4 K7 f' Y5 V' v<declare-styleable name = "名称">
<attr name = "textColor" format = "color" />
</declare-styleable>
(2)属性使用:
<TextView
android:layout_width = "42dip"! y$ @/ F- U( V- L! A
android:layout_height = "42dip"
android:textColor = "#00FF00"
/>
3. boolean:布尔值。
- K1 _1 J4 k- N3 \(1)属性定义:
8 ~9 t! V& O6 ~1 s7 H8 P6 r$ I2 p7 u<declare-styleable name = "名称">
<attr name = "focusable" format = "boolean" />
</declare-styleable>
(2)属性使用:
" _- S& P/ ` G$ P1 L0 ~( r<Button
android:layout_width = "42dip"
android:layout_height = "42dip"
android:focusable = "true"
/>
4. dimension:尺寸值。
7 y& d2 X& x) W: C$ P(1)属性定义:
<declare-styleable name = "名称">
<attr name = "layout_width" format = "dimension" />
</declare-styleable>
# v# L' ? J$ V* J(2)属性使用:
5 T6 ]3 ]( `+ C4 Z6 `<Button
android:layout_width = "42dip"- ?; r7 P# ], i$ ~
android:layout_height = "42dip"
/>
5. float:浮点值。
7 }; j7 }# [! L6 F* o0 k4 y(1)属性定义:
<declare-styleable name = "AlphaAnimation">
<attr name = "fromAlpha" format = "float" />) K" X% W! `. u0 O( I& b
<attr name = "toAlpha" format = "float" />
</declare-styleable>
(2)属性使用:
<alpha
android:fromAlpha = "1.0"
android:toAlpha = "0.7"
/>
6. integer:整型值。
7 t$ X& I9 R7 s5 J5 Q! B: |(1)属性定义:
. _& x) A, i( o; x, k<declare-styleable name = "AnimatedRotateDrawable">
<attr name = "visible" />1 F1 E# r9 k: A4 c
<attr name = "frameDuration" format="integer" />
<attr name = "framesCount" format="integer" />
<attr name = "pivotX" />
<attr name = "pivotY" />2 i0 R' M3 a1 `
<attr name = "drawable" />
</declare-styleable>
0 D M+ A5 F' D/ C+ q6 S' R(2)属性使用:
9 ?. x7 C8 K& o% j! K% j K# N<animated-rotate
xmlns:android = "http://schemas.android.com/apk/res/android"
android:drawable = "@drawable/图片ID"
android:pivotX = "50%"
android:pivotY = "50%"
android:framesCount = "12"
android:frameDuration = "100"
/>
4 g" D3 g( _$ Z7 }0 w8 G/ Q7. string:字符串。
(1)属性定义:
' ] m6 W# P/ ]! X Z; G" n* l. w <declare-styleable name = "MapView">
<attr name = "apiKey" format = "string" />
</declare-styleable>
(2)属性使用:
<com.google.android.maps.MapView
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"; W) [3 O% I/ ^- m& o
android:apiKey = "0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g"
/>
0 F& U: h$ w- }: A3 {8. fraction:百分数。
(1)属性定义:
5 g* R8 ^' z0 E <declare-styleable name="RotateDrawable">
<attr name = "visible" />
<attr name = "fromDegrees" format = "float" />
<attr name = "toDegrees" format = "float" /># n' s& N1 q; _# `
<attr name = "pivotX" format = "fraction" />
<attr name = "pivotY" format = "fraction" />3 ]$ ] }. `3 u3 y
<attr name = "drawable" />
</declare-styleable>
(2)属性使用:
<rotate
xmlns:android = "http://schemas.android.com/apk/res/android"
android:interpolator = "@anim/动画ID"
android:fromDegrees = "0"
android:toDegrees = "360"
android:pivotX = "200%"
android:pivotY = "300%"
android:duration = "5000"
android:repeatMode = "restart"
android:repeatCount = "infinite"
/>
9. enum:枚举值。
(1)属性定义:
<declare-styleable name="名称">; |7 ^1 L1 ^* m" `" J8 o H' r$ j, x
<attr name="orientation">
<enum name="horizontal" value="0" />5 j' l. `" I& T# ?1 U6 ?! S% j
<enum name="vertical" value="1" />' O" p4 V* x7 b8 P7 i- k; a* U5 H
</attr>
</declare-styleable>
(2)属性使用:
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
>6 t* N( W$ y* a. [2 V
</LinearLayout>
10. flag:位或运算。
" O3 A. S) `: O% G(1)属性定义:
<declare-styleable name="名称">
<attr name="windowSoftInputMode">
<flag name = "stateUnspecified" value = "0" />9 m. u+ i( U" _! {$ k, E- a
<flag name = "stateUnchanged" value = "1" />
<flag name = "stateHidden" value = "2" />
<flag name = "stateAlwaysHidden" value = "3" />& j# ^6 T I3 L# y A, Y
<flag name = "stateVisible" value = "4" />
<flag name = "stateAlwaysVisible" value = "5" />
<flag name = "adjustUnspecified" value = "0x00" /># L5 j6 T5 _/ }
<flag name = "adjustResize" value = "0x10" />
<flag name = "adjustPan" value = "0x20" />$ x" X# A/ t* V" }& W2 E
<flag name = "adjustNothing" value = "0x30" />+ M6 q, T0 ]0 z6 [
</attr>
</declare-styleable>
(2)属性使用:
<activity
android:name = ".StyleAndThemeActivity"
android:label = "@string/app_name" U6 B. f: N% X% C
android:windowSoftInputMode = "stateUnspecified | stateUnchanged | stateHidden">
<intent-filter>
<action android:name = "android.intent.action.MAIN" />* k" Q& a i2 w1 o& t
<category android:name = "android.intent.category.LAUNCHER" />8 ?9 s* \, R; X6 D
</intent-filter>
</activity>
注意:
8 \' X' @6 z" b3 F6 l6 q% X: e7 G属性定义时可以指定多种类型值。
! E) N0 d# s! f& F: @9 Z(1)属性定义:
<declare-styleable name = "名称">
<attr name = "background" format = "reference|color" />
</declare-styleable>
/ V: ~0 _) w3 r" j$ X' n(2)属性使用:
4 Y! t0 K: o! J% B9 O8 _% d( ~- X+ q" \<ImageView
android:layout_width = "42dip"
android:layout_height = "42dip"+ a, F9 V1 u7 s# \2 I- p4 e% }
android:background = "@drawable/图片ID|#00FF00"
/>
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- Android中自定义属性的格式详解
- UML总结
- linux启用无线网卡上网
- 《Java并发编程实战》---线程安全性---不可变性
- 枚举类型的声明
- 《Java并发编程实战》---线程安全性---对象的发布
- Android中自定义属性的格式详解
- 第五章思维导图
- Android应用盈利广告平台的嵌入方法详解
- Android中的网络编程系列(一):URLConnection
- 理解一般指针和指向指针的指针
- android 广告平台,万普平台使用心得
- java 集合遍历
- block引用局部变量
- 上机作业4