Android自定义属性,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" />
摘自:http://blog.csdn.net/pgalxx/article/details/6766677
Android自定义属性,format详解的更多相关文章
- android自定义控件(三) 增加内容 自定义属性 format详解
转自 http://www.gisall.com/html/35/160435-5369.html 1. reference:参考某一资源ID. (1)属性定义: <declare-stylea ...
- 【转】declare-styleable的使用(自定义控件) 以及declare-styleable中format详解
原文网址:http://www.cnblogs.com/622698abc/p/3348692.html declare-styleable是给自定义控件添加自定义属性用的 1.首先,先写attrs. ...
- Android 自定义 View 详解
View 的绘制系列文章: Android View 绘制流程之 DecorView 与 ViewRootImpl Android View 的绘制流程之 Measure 过程详解 (一) Andro ...
- android:ToolBar详解
android:ToolBar详解(手把手教程) 泡在网上的日子 发表于 2014-11-18 12:49 第 124857 次阅读 ToolBar 42 来源 http://blog.mosil.b ...
- Android之canvas详解
首先说一下canvas类: Class Overview The Canvas class holds the "draw" calls. To draw something, y ...
- 【转】Android Canvas绘图详解(图文)
转自:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1212/703.html Android Canvas绘图详解(图文) 泡 ...
- 【转】Java魔法堂:String.format详解
Java魔法堂:String.format详解 目录 一.前言 二.重载方法 三.占位符 四.对字符.字符串进行格式化 五.对整数进行格式化 六. ...
- Android 核心分析 之八Android 启动过程详解
Android 启动过程详解 Android从Linux系统启动有4个步骤: (1) init进程启动 (2) Native服务启动 (3) System Server,Android服务启动 (4) ...
- Android GLSurfaceView用法详解(二)
输入如何处理 若是开发一个交互型的应用(如游戏),通常需要子类化 GLSurfaceView,由此可以获取输入事件.下面有个例子: java代码: package eoe.ClearTes ...
- Android编译过程详解(一)
Android编译过程详解(一) 注:本文转载自Android编译过程详解(一):http://www.cnblogs.com/mr-raptor/archive/2012/06/07/2540359 ...
随机推荐
- yii2图片验证码
控制器LoginController.php <?php namespace backend\controllers; use Yii; use yii\debug\models\search\ ...
- hdu 5493 Queue treap实现将元素快速插入到第i个位置
input T 1<=T<=1000 n 1<=n<=100000 h1 k1 h2 k2 ... ... hn kn 1<=hi<=1e9 0<=ki&l ...
- cocoaPods的安装方法
1.打开终端 2.先升级Gem sudo gem update --system 3.切换cocoapods的数据源 [先删除,再添加,查看] gem sources --remove https:/ ...
- java并发编程框架 Executor ExecutorService invokeall
首先介绍两个重要的接口,Executor和ExecutorService,定义如下: public interface Executor { void execute(Runnable command ...
- csuoj1009
AC代码: #include <iostream>#include <iomanip>using namespace std;//计算数学期望值,可以自己直接通过数组的方式来实 ...
- c专家编程---优先级规则
对于一些复杂的类型组合,总是搞不明白,今天阅读了“优先级规则”这块,有了进一步的理解,特将规则记在此处,供自己学习查询使用. 优先级规则: A.声明从它的名字开始读取,然后按照优先级顺序依次读取 B. ...
- java FLOAT
System.out.println(""+ 1/2); 得不到0.5,只能得到0. 要想打印出浮点数,必须除数和被除数至少有一个是浮点数,像这样: System.out.prin ...
- flash Ane
1.ANE简介 Adobe AIR Native Extension,Adobe AIR的本地扩展,简称ANE.什么叫本地扩展?因为Adobe AIR是跨平台的一个运行时,可以在Windows,Mac ...
- ibatis resultMap 结果集映射
1.结果集映射 就是将返回的记录,逐个字段映射到java对象上:如果数据库字段与java对象的成员变量名对应的话,则使用resultClas即可 2.实现 结合 ibatis初探这篇文章中提到的pro ...
- 用sql server的sql语句算一个empty GUID
在C#中得到一个empty GUID的方法是: Guid id= Guid.Empty; 那么在SQL Server Management Studio中怎样得到一个empty GUID呢? 方法有两 ...