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" />

摘自:http://blog.csdn.net/pgalxx/article/details/6766677

Android自定义属性,format详解的更多相关文章

  1. android自定义控件(三) 增加内容 自定义属性 format详解

    转自 http://www.gisall.com/html/35/160435-5369.html 1. reference:参考某一资源ID. (1)属性定义: <declare-stylea ...

  2. 【转】declare-styleable的使用(自定义控件) 以及declare-styleable中format详解

    原文网址:http://www.cnblogs.com/622698abc/p/3348692.html declare-styleable是给自定义控件添加自定义属性用的 1.首先,先写attrs. ...

  3. Android 自定义 View 详解

    View 的绘制系列文章: Android View 绘制流程之 DecorView 与 ViewRootImpl Android View 的绘制流程之 Measure 过程详解 (一) Andro ...

  4. android:ToolBar详解

    android:ToolBar详解(手把手教程) 泡在网上的日子 发表于 2014-11-18 12:49 第 124857 次阅读 ToolBar 42 来源 http://blog.mosil.b ...

  5. Android之canvas详解

    首先说一下canvas类: Class Overview The Canvas class holds the "draw" calls. To draw something, y ...

  6. 【转】Android Canvas绘图详解(图文)

    转自:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1212/703.html Android Canvas绘图详解(图文) 泡 ...

  7. 【转】Java魔法堂:String.format详解

    Java魔法堂:String.format详解     目录     一.前言    二.重载方法     三.占位符     四.对字符.字符串进行格式化     五.对整数进行格式化     六. ...

  8. Android 核心分析 之八Android 启动过程详解

    Android 启动过程详解 Android从Linux系统启动有4个步骤: (1) init进程启动 (2) Native服务启动 (3) System Server,Android服务启动 (4) ...

  9. Android GLSurfaceView用法详解(二)

    输入如何处理       若是开发一个交互型的应用(如游戏),通常需要子类化 GLSurfaceView,由此可以获取输入事件.下面有个例子: java代码: package eoe.ClearTes ...

  10. Android编译过程详解(一)

    Android编译过程详解(一) 注:本文转载自Android编译过程详解(一):http://www.cnblogs.com/mr-raptor/archive/2012/06/07/2540359 ...

随机推荐

  1. 关于MTK平台SIM-ME Lock的配置方案

    针对一些运营商的锁网需求,MTK平台已经对其有很好的支持.绝大多数的海外需求可以通过直接配置相关文件来完成.这里简单描述一下配置方法,不做原理分析. 相关数据结构分析: Modem中与SML锁网配置相 ...

  2. G - 娜娜梦游仙境系列——梦醒

    G - 娜娜梦游仙境系列——梦醒 Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others) ...

  3. JavaScript “类”定义 继承 闭包 封装

    一.Javascript “类”: 类:在面向对象编程中,类(class)是对象(object)的模板,定义了同一组对象(又称"实例")共有的属性和方法. Javascript是一 ...

  4. 最全ajax函数

    function ajax(method, url, data, success) { var xhr = null; try { xhr = new XMLHttpRequest(); } catc ...

  5. mysql之TIMESTAMP(时间戳)用法详解 [http://www.jb51.net/article/51794.htm]

    一.TIMESTAMP的变体 TIMESTAMP时间戳在创建的时候可以有多重不同的特性,如: 1.在创建新记录和修改现有记录的时候都对这个数据列刷新: TIMESTAMP DEFAULT CURREN ...

  6. 《C++ Primer》之指向函数的指针

    函数指针是指指向函数而非指向对象的指针.像其他指针一样,函数指针也指向某个特定的类型.函数类型由其返回类型以及形参表确定,而与函数名无关: // pf points to function retur ...

  7. VBS常用使用技巧

    (一)VBS常用函数使用笔记: 1.Msgbox语法:msgbox "对话框内容", , "对话框的标题" 2.inputbox是VBS内建的函数,可以接受输入 ...

  8. hdu_3565_Bi-peak Number(数位DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3565 题意:给你一个区间,让你找这个区间内有两个山峰的数的最大和,什么是两个山峰,比如121121   ...

  9. Storm官方帮助手册翻译(下)

    使用其他语言编写Bolt Bolt可以使用任意语言编写.用另外一种语言编写Bolt来作为子进程运行.Storm会在标准输入输出的基础上使用Json来与子进程通信.通信协议之需要一个100行的适配器库, ...

  10. app调用支付宝支付 笔记

    1.提交各种申请 2.通过后进入支付宝开放平台  --> 管理中心 -->创建应用  --> 填写相关信息 提交等待审核通过(1,2天)   3.下载集成包(https://doc. ...