Android自定义属性时format选项可以取用的值

1. reference:参考某一资源ID。

(1)属性定义:

  1. <declare-styleable name="名称">
  2. <attr format="reference" name="background" />
  3. </declare-styleable>

(2)属性使用:

  1. <ImageView
  2. android:layout_width="42dip"
  3. android:layout_height="42dip"
  4. android:background="@drawable/图片ID" />

2. color:颜色值。

(1)属性定义:

  1. <declare-styleable name="名称">
  2. <attr format="color" name="textColor" />
  3. </declare-styleable>

(2)属性使用:

  1. <TextView
  2. android:layout_width="42dip"
  3. android:layout_height="42dip"
  4. android:textColor="#00FF00" />

3. boolean:布尔值。

(1)属性定义:

  1. <declare-styleable name="名称">
  2. <attr format="boolean" name="focusable" />
  3. </declare-styleable>

(2)属性使用:

  1. <Button
  2. android:layout_width="42dip"
  3. android:layout_height="42dip"
  4. android:focusable="true" />

4. dimension:尺寸值。

(1)属性定义:

  1. <declare-styleable name="名称">
  2. <attr format="dimension" name="layout_width" />
  3. </declare-styleable>

(2)属性使用:

  1. <Button
  2. android:layout_width="42dip"
  3. android:layout_height="42dip" />

5. float:浮点值。

(1)属性定义:

  1. <declare-styleable name="AlphaAnimation">
  2. <attr format="float" name="fromAlpha" />
  3. <attr format="float" name="toAlpha" />
  4. </declare-styleable>

(2)属性使用:

  1. <alpha
  2. android:fromAlpha="1.0"
  3. android:toAlpha="0.7" />

6. integer:整型值。

(1)属性定义:

  1. <declare-styleable name="AnimatedRotateDrawable">
  2. <attr format="integer" name="frameDuration" />
  3. <attr format="integer" name="framesCount" />
  4. </declare-styleable>

(2)属性使用:

  1. <animated-rotate
  2. android:frameDuration="100"
  3. android:framesCount="12"
  4. />

7. string:字符串。

(1)属性定义:

  1. <declare-styleable name="MapView">
  2. <attr format="string" name="apiKey" />
  3. </declare-styleable>

(2)属性使用:

  1. <com.google.android.maps.MapView
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent"
  4. android:apiKey="0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g" />

8. fraction:百分数。

(1)属性定义:


  1. <declare-styleable name="RotateDrawable">
  2. <attr format="fraction" name="pivotX" />
  3. <attr format="fraction" name="pivotY" />
  4. </declare-styleable>

(2)属性使用:

  1. <rotate
  2. android:pivotX="200%"
  3. android:pivotY="300%"
  4. />

9. enum:枚举值。

(1)属性定义:

  1. <declare-styleable name="名称">
  2. <attr name="orientation">
  3. <enum name="horizontal" value="0" />
  4. <enum name="vertical" value="1" />
  5. </attr>
  6. </declare-styleable>

(2)属性使用:

  1. <LinearLayout
  2. android:orientation="vertical" >
  3. </LinearLayout>

10. flag:位或运算。

(1)属性定义:

  1. <declare-styleable name="名称">
  2. <attr name="windowSoftInputMode">
  3. <flag name="stateUnspecified" value="0" />
  4. <flag name="stateUnchanged" value="1" />
  5. <flag name="stateHidden" value="2" />
  6. <flag name="stateAlwaysHidden" value="3" />
  7. <flag name="stateVisible" value="4" />
  8. <flag name="stateAlwaysVisible" value="5" />
  9. <flag name="adjustUnspecified" value="0x00" />
  10. <flag name="adjustResize" value="0x10" />
  11. <flag name="adjustPan" value="0x20" />
  12. <flag name="adjustNothing" value="0x30" />
  13. </attr>
  14. </declare-styleable>

(2)属性使用:

  1. <activity
  2. android:windowSoftInputMode="stateUnspecified | stateUnchanged | stateHidden" >
  3. </activity>

注意:属性定义时可以指定多种类型值:

(1)属性定义:

  1. <declare-styleable name="名称">
  2. <attr format="reference|color" name="background" />
  3. </declare-styleable>

(2)属性使用:

  1. <ImageView
  2. android:layout_width="42dip"
  3. android:layout_height="42dip"
  4. android:background="@drawable/图片ID|#00FF00" />
时间: 2024-08-05 19:35:47

Android自定义属性时format选项可以取用的值的相关文章

Android自定义属性,format详解

博客园 博问 闪存 首页 新随笔 联系 管理 订阅 随笔- 90  文章- 6  评论- 57 Android自定义属性,format详解 1. reference:参考某一资源ID. (1)属性定义: <declare-styleable name = "名称"> <attr name = "background" format = "reference" /> </declare-styleable> (2

Android自定义属性时TypedArray的使用方法

有时候android传统的页面布局不足以满足我们的需求,常常需要自己定义view,通常继承View,然后重写构造方法以及onDraw等函数,再具体实现自己定义的复杂view.我们知道在给控件赋属性时,通常使用的是android系统自带的属性,比如 android:layout_height="wrap_content",除此之外,我们亦可以自己定义属性,这样在使用的时候我们就可以使用形如 myapp:myTextSize="20sp"的方式了,步骤大致如下: 1 在

Android-深入理解android自定义属性(AttributeSet,TypedArray)

属性 自定义属性,首先要定义出来属性,我们新建一个attrs.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <attr name="textSize0" format="dimension" /> <declare-styleable name="button1"> <attr name=

Android 自定义属性

Android自定义属性我们自定义控件中是经常用到的,自定义属性可以在我们的xml布局文件中使用,这样可以减少代码量,也增加了代码的健壮性和可阅读性.所以,在掌握自定义控件之前要首先掌握好怎样自定义属性. 首先来看看自定属性都有哪些? values/attrs.xml 中可定义的属性类型有如下几个: 1. reference:参考某一资源ID.<attr name = "background" format = "reference" /> 2. col

Android自定义属性:attr.xml 与 TypedArray

1.attr.xml <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="MyView"> <attr name="textColor" format="color" /> <attr name="textSize" format=&q

记录我在百度地图开发和ArcGIS for Android开发时出现的一些错误及解决方案(后续更新)

[1]The import com.baidu.mapapi.map.Geometry conflicts with a type defined in the same file 解决:百度api包下的Geometry和某个类名相冲突,将类名换成另外的名字,不要和百度相关类里面的类名相同 [2]java.lang.ClassCastException: 解决:类型转换错误.查看Test_Geometry项目的Mainfest.xml清单文件,在<applicaiton>标签里面少了对Myap

Android 开发时如何正确获取使用扩展存储路径

Android 开发时如何正确获取使用扩展存储路径 先介绍一下Android的存储 在 2.x 版本中,Android设备都是单存储,第三方App写文件,必须申请 WRITE_EXTERNAL_STORAGE 权限: 在4.0之后,Android设备开始有了内置闪存,即 primary storage,并且可以外置SD卡,即 secondary external storage device: WRITE_EXTERNAL_STORAGE 权限变成了仅仅控制 primary storage,同时

在Eclipse中开发Android程序时截屏的方法

在Eclipse中调试Android程序时,有时需要将程序截图保存到电脑中.步骤如下: Window --- Show View --- Other : 在弹出的窗口中,选择 Devices : 在打开的Device选项卡中,选择要截图的设备或模拟器,然后点击旁边的截图按钮: 在弹出的窗口中,点击 Save 按钮,将程序截图保存到指定的目录中即可.

(转)安装Android SDK时遇到Failed to rename directory

安装Android SDK时遇到Failed to rename directory E:\Java\Android SDK\android-sdk_r06-windows\android-sdk-windows\tools to E:\Java\Android SDK\android-sdk_r06-windows\android-sdk-windows\temp\ToolPackage.old01     这样的问题?总是提示无法改名?     解决方法如下:     1.备份tools文件