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. Zookeeper 启动错误

    启动后日志如下 : 2016-09-14 05:51:19,449 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeade ...

  2. samba server 设置

     samba server  设置yum install samba.x86_64systemctl start smb.servicesystemctl enable smb.servicesamb ...

  3. 12C dbca silent

    dbca needs a template file to create a database. These template can be found in $ORACLE_HOME/assista ...

  4. js解析php返回的json数据无法获取length的问题分析

    1.问题出现的过程,js解析php json_encode 的数据,无法获取长度信息,提示undefined   debug:       首先打印查看了php encode后的数据,返现最外层是一个 ...

  5. jquery源码阅读(1)

    每天坚持阅读一定量的的jquery代码,积少成多!加油加油! jquery-2.2.1的9161~9194行 1 if ( typeof define === "function" ...

  6. Robotium第一天:搭建环境测试微信

    因为要在命令行下运行一些android的工具,所以配置一些环境变量会比较方便: 遇到问题: java -jar re-sign.jar 出现提示android路径没有配置好: 需要配置如下: 配置AN ...

  7. hdu_1513_Palindrome(LCS+滚动数组)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 题意:给你一个字符串,问你最少插入多少个字符使其为回文字符. 题解:将字符串倒着保存,然后求一下 ...

  8. nefu 115 斐波那契的整除

    Description 已知斐波那契数列有如下递归定义,f(1)=1,f(2)=1, 且n>=3,f(n)=f(n-1)+f(n-2),它的前几项可以表示为1, 1,2 ,3 ,5 ,8,13, ...

  9. 【超级干货】手机移动端WEB资源整合:转载

    转载于:http://www.w3cfuns.com/notes/24611/fbba9cbd616e795360ea45515494aa53.html meta基础知识 H5页面窗口自动调整到设备宽 ...

  10. Linux 配置脚本 启动服务

    之前在mac安装了php和nginx每次都用一堆命令重启 今天没事情干,心血来潮,自己研究写了一段shell脚本来重启 首先vim /usr/sbin/pn 代码如下 #! /bin/bash php ...