自定义控件 attrs.xml
来源:互联网 发布:牛客网算法视频下载 编辑:程序博客网 时间:2024/06/05 14:50
attrs.xml format属性说明:
- <attr name="xxx"<strong> format</strong>="..."/>
- "reference" //引用
- "color" //颜色
- "boolean" //布尔值
- "dimension" //尺寸值
- "float" //浮点值
- "integer" //整型值
- "string" //字符串
- "fraction" //百分数,比如200%
- 枚举型的格式:
- <attr name="orientation">
- <enum name="horizontal" value="0" />
- <enum name="vertical" value="1" />
- </attr>
- XML文件中使用:
- android:orientation = "vertical"
- 标志位、位或运算,格式如下:
- <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>
- XML文件中使用:
- android:windowSoftInputMode = "stateUnspecified | stateUnchanged | stateHidden">
- 属性定义可以指定多种类型:
- <attr name = "background" format = "reference|color" />
- XML文件中使用:
- android:background = "@drawable/图片ID|#00FF00"
attrs.xml format使用说明:
- 1. reference:参考某一资源ID。
- (1)属性定义:
- <declare-styleable name = "名称">
- <attr name = "background" format = "reference" />
- </declare-styleable>
- (2)属性使用:
- <ImageView
- android:layout_width = "42dip"
- android:layout_height = "42dip"
- android:background = "@drawable/图片ID"
- />
- 2. color:颜色值。
- (1)属性定义:
- <declare-styleable name = "名称">
- <attr name = "textColor" format = "color" />
- </declare-styleable>
- (2)属性使用:
- <TextView
- android:layout_width = "42dip"
- android:layout_height = "42dip"
- android:textColor = "#00FF00"
- />
- 3. boolean:布尔值。
- (1)属性定义:
- <declare-styleable name = "名称">
- <attr name = "focusable" format = "boolean" />
- </declare-styleable>
- (2)属性使用:
- <Button
- android:layout_width = "42dip"
- android:layout_height = "42dip"
- android:focusable = "true"
- />
- 4. dimension:尺寸值。
- (1)属性定义:
- <declare-styleable name = "名称">
- <attr name = "layout_width" format = "dimension" />
- </declare-styleable>
- (2)属性使用:
- <Button
- android:layout_width = "42dip"
- android:layout_height = "42dip"
- />
- 5. float:浮点值。
- (1)属性定义:
- <declare-styleable name = "AlphaAnimation">
- <attr name = "fromAlpha" format = "float" />
- <attr name = "toAlpha" format = "float" />
- </declare-styleable>
- (2)属性使用:
- <alpha
- android:fromAlpha = "1.0"
- android:toAlpha = "0.7"
- />
- 6. integer:整型值。
- (1)属性定义:
- <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)属性使用:
- <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:字符串。
- (1)属性定义:
- <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"
- android:apiKey = "0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g"
- />
- 8. fraction:百分数。
- (1)属性定义:
- <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)属性使用:
- <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="名称">
- <attr name="orientation">
- <enum name="horizontal" value="0" />
- <enum name="vertical" value="1" />
- </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"
- >
- </LinearLayout>
- 10. flag:位或运算。
- (1)属性定义:
- <declare-styleable 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)属性使用:
- <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>
- 注意:
- 属性定义时可以指定多种类型值。
- (1)属性定义:
- <declare-styleable name = "名称">
- <attr name = "background" format = "reference|color"/>
- </declare-styleable>
- (2)属性使用:
- <ImageView
- android:layout_width = "42dip"
- android:layout_height = "42dip"
- android:background = "@drawable/图片ID|#00FF00"
- />
0 0
- 自定义控件 attrs.xml
- android 自定义控件之xml---- attributeset attrs
- android中自定义的控件,使用自定义属性attrs.xml
- 自定义控件属性TypedArray和attrs.xml和AttributeSet
- 自定义控件的属性(attrs.xml,TypedArray)的使用
- android 无(attrs.xml) 的自定义控件方法
- android 使用attrs自定义控件
- 自定义控件attrs属性介绍
- Android 自定义属性 attrs.xml
- 【Android】自定义属性 attrs.xml
- Android 自定义属性 attrs.xml
- 使用attrs.xml自定义属性
- 自定义view圆环attrs.xml
- 自定义控件的自定义的属性attrs.xml下的declare-styleable中format详解
- Android自定义控件热身——自定义属性attrs.xml中format详解
- 自定义控件的自定义的属性attrs.xml下的declare-styleable中format详解
- Android自定义控件中的自定义attrs
- 自定义控件Topbar、自定义属性attrs
- 三步实现响应式网页布局
- socket、 send、recv、阻塞相关
- git提交修改到远程仓库
- 第二讲--------缩略图放大
- WWDC 2014 Session笔记 - iOS界面开发的大一统
- 自定义控件 attrs.xml
- VS2013 带命令行参数的调试问题 解决方案
- eclipse下如何查看jdk源码
- 《浪潮之巅》之IT Laws---IT 定律
- 面试题之三
- 老程序员:当编程属于第二职业的时候
- UISearchBar
- 我是如何自学编程的——“3遍读书法”
- 一个包含error:function的ajax请求