Android自定义属性 format的深入解析_Android

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

时间: 2024-08-01 21:07:28

Android自定义属性 format的深入解析_Android的相关文章

Android自定义属性 format的深入解析

以下是对Android中的自定义属性format进行了详细的分析介绍,需要的朋友可以过来参考下   1. reference:参考某一资源ID.(1)属性定义: 复制代码 代码如下: <declare-styleable name = "名称">    <attr name = "background" format = "reference" /> </declare-styleable> (2)属性使用:

Android 滑动拦截实例代码解析_Android

废话不多说了,直接给大家贴代码了,具体代码如下所示: package demo.hq.com.fby; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.widget.LinearLayout; /** * Created by huqing on 2016/12/7.

Android ActionBar制作时钟实例解析_Android

本文实例为大家分享了Android ActionBar制作时钟的具体代码,供大家参考,具体内容如下 1. MainActivity.java   package com.example.days19actionbar07custom; import com.example.days19actionbar07custom.R; import android.app.Activity; import android.os.Bundle; import android.view.Menu; impor

Android Activity启动模式全面解析_Android

在android里,有4种activity的启动模式,分别为: "standard" (默认) "singleTop" "singleTask" "singleInstance" 在Android应用中, Activity是最核心的组件, 如何生成一个Activity实例, 可以选择不同的启动模式, 即LaunchMode. 启动模式主要包括: standard, singleTop, singleTask, singleIn

android textview 显示html方法解析_Android

现在网络的繁盛时代,光文字是不能满足人们的胃口的,图片,flash,音频,视频就成为浏览网页的主流显示,在手机上也一样.在手机上显示从网络端获取的数据显示,大家很自然的想起两种方式,一种就是webview,一种就是TextView.当然webView直接显示html页面就行了,我主要说的TextView显示html内容. 首先,说下TextView到底支持那些标签呢,通过对源码的查看,发现Textview可以解析一部分html标签,如: 复制代码 代码如下: <a href="...&qu

Android RecyclerView艺术般的控件使用完全解析_Android

RecyclerView出现已经有一段时间了,相信大家肯定不陌生了,大家可以通过导入support-v7对其进行使用. 据官方的介绍,该控件用于在有限的窗口中展示大量数据集,其实这样功能的控件我们并不陌生,例如:ListView.GridView. 那么有了ListView.GridView为什么还需要RecyclerView这样的控件呢?整体上看RecyclerView架构,提供了一种插拔式的体验,高度的解耦,异常的灵活,通过设置它提供的不同LayoutManager,ItemDecorati

android之App Widget开发实例代码解析_Android

Android Widget开发案例实现是本文要介绍的内容,主要是来了解并学习Android Widget开发应用,今天我们要写一下Android Widget的开发,由于快点凌晨,我就不说的太具体了,同志们就模仿吧! 首先继续了解下App Widget框架的主要的类: AppWidgetProvider:继承自BroadcastReceiver,在App Widget应用update,enable,disable和deleted时接受通知.其中onUpdate,onReceive是最常用到的方

Android Volley框架全面解析_Android

 Volley简介 我们平时在开发Android应用的时候不可避免地都需要用到网络技术,而多数情况下应用程序都会使用HTTP协议来发送和接收网络数据.Android系统中主要提供了两种方式来进行HTTP通信,HttpURLConnection和HttpClient,几乎在任何项目的代码中我们都能看到这两个类的身影,使用率非常高. 不过HttpURLConnection和HttpClient的用法还是稍微有些复杂的,如果不进行适当封装的话,很容易就会写出不少重复代码.于是乎,一些Android网络

Android中gson、jsonobject解析JSON的方法详解_Android

JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据交换.JSON采用兼容性很高的文本格式,同时也具备类似于C语言体系的行为. JSON对象: JSON中对象(Object)以"{"开始, 以"}"结束. 对象中的每一个item都是一个key-value对, 表现为"key:value"的形式, ke