自定义控件 attrs.xml
attrs.xml format属性说明:
- <attrname="xxx"strong>format</>="..."/>
copy
"reference"//引用
- "color"//颜色
- "boolean"//布尔值
- "dimension"//尺寸值
- "float"//浮点值
- "integer"//整型值
- "string"//字符串
- "fraction"//百分数,比如200%
枚举型的格式:
- attrname="orientation">
- enumname="horizontal"value="0"/>
- enumname="vertical"value="1"/>
- attr>
XML文件中使用:
- android:orientation="vertical"
标志位、位或运算,格式如下:
- attrname="windowSoftInputMode"flagname="stateUnspecified"value="0"flagname="stateUnchanged"value="1"flagname="stateHidden"value="2"flagname="statealwaysHidden"value="3"flagname="stateVisible"value="4"flagname="statealwaysVisible"value="5"flagname="adjustUnspecified"value="0x00"flagname="adjustResize"value="0x10"flagname="adjustPan"value="0x20"flagname="adjustnothing"value="0x30"copy
android:windowSoftInputMode="stateUnspecified|stateUnchanged|stateHidden"copy
copy
属性定义可以指定多种类型:
- attrname="background"format="reference|color"/>
android:background="@drawable/图片ID|#00FF00"
attrs.xml format使用说明:
copy
1.reference:参考某一资源ID。
- (1)属性定义:
- declare-styleablename="名称">
- attrname="background"format="reference"declare-styleable (2)属性使用:
- ImageView
- android:layout_width="42dip"
- android:layout_height="42dip"
- android:background="@drawable/图片ID"
- 2.color:颜色值。
- (1)属性定义:
- attrname="textColor"format="color" (2)属性使用:
- TextView
- android:layout_width="42dip"
- android:layout_height="42dip"
- android:textColor="#00FF00"
- 3.boolean:布尔值。
- attrname="focusable"format="boolean"Button
- android:focusable="true"
- 4.dimension:尺寸值。
- attrname="layout_width"format="dimension"Button
- 5.float:浮点值。
- declare-styleablename="AlphaAnimation"attrname="fromAlpha"format="float"attrname="toAlpha"format="float"alpha
- android:fromAlpha="1.0"
- android:toAlpha="0.7"
- 6.integer:整型值。
- declare-styleablename="AnimatedRotateDrawable"attrname="visible"attrname="frameDuration"format="integer"attrname="framesCount"format="integer"attrname="pivotX"attrname="pivotY"attrname="drawable"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"
- 7.string:字符串。
- declare-styleablename="MapView"attrname="apiKey"format="string"com.google.android.maps.MapView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:apiKey="0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g"
- 8.fraction:百分数。
- declare-styleablename="RotateDrawable"attrname="fromdegrees"format="float"attrname="todegrees"format="float"attrname="pivotX"format="fraction"attrname="pivotY"format="fraction"rotatexmlns: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:枚举值。
- LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- LinearLayout 10.flag:位或运算。
- activity
- android:name=".StyleAndThemeActivity"
- android:label="@string/app_name"
- android:windowSoftInputMode="stateUnspecified|stateUnchanged | stateHidden"intent-filteractionandroid:name="android.intent.action.MAIN"categoryandroid:name="android.intent.category.LAUNCHER"activity 注意:
- 属性定义时可以指定多种类型值。
- attrname="background"format="reference|color" android:background="@drawable/图片ID|#00FF00"
- />
相关文章
XML轻松学习手册