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/sunny2come/article/details/6996943

时间: 2024-10-12 23:43:27

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 自定义属性

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

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学习之旅(五十二)

android资源的类型 android资源的存储方式

android:inputType参数类型说明

android:inputType参数类型说明 android:inputType="none"--输入普通字符 android:inputType="text"--输入普通字符 android:inputType="textCapCharacters"--输入普通字符 android:inputType="textCapWords"--单词首字母大小 android:inputType="textCapSenten

Android获取当前时间的android.text.format.Time已过时

之前使用的 Time time = new android.text.format.Time(); time.setToNow(); String timeNow = time.format("%Y%m%d%H%M%S"); 来获取当前时间,但是在android22中提示过时 deprecated 然后找了下,实在不知道用哪个好,只好试试这个 Calendar calendar = Calendar.getInstance(); String timeNow = new SimpleD

(转)android:inputType参数类型说明

android:inputType参数类型说明 android:inputType="none"--输入普通字符 android:inputType="text"--输入普通字符 android:inputType="textCapCharacters"--输入普通字符 android:inputType="textCapWords"--单词首字母大小 android:inputType="textCapSenten

Xamarin.Android编译CPU类型选择方式

Xamarin.Android编译CPU类型选择方式 在Xamarin.Android编译的时候,默认提供了5种CPU类型供大家选择.它们分别为armeabi.armeabi-v7a.arm64-v8a.x86和x86_64.其中,前三项都是针对ARM规范的CPU,后面两项是Intel芯片的.其中,64表示64位CPU.这里针对ARM的三类,具体讲解一下.armeabi是针对基于 ARM* v5TE规范的CPU.这类CPU支持软浮点运算,但不支持硬件加速浮点运算.armeabi-v7a是针对 A