`

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"

                     />



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mayingcai1987/archive/2011/03/01/6216655.aspx
分享到:
评论

相关推荐

    Android开发之如何自定义数字键盘详解

    这篇文章是介绍Android中自定义键盘的一些套路,通过定义一个数字键盘为例,本篇的文章语言是基于Kotlin实现的,如果还没有用或者不熟悉该语言的同学,可以自己补习,我之前也写过入门文章。 效果图 github:源码...

    《Android自定义组件开发详解》

    6.4.2 读取来自style和theme中的属性 181 6.5 案例1:圆形ImageView组件 186 6.6 案例2:验证码组件CodeView 190 6.7 练习作业 202 第七章 自定义容器 204 7.1 概述 204 7.2 ViewGroup类 205 7.2.1 ViewGroup常用...

    android开发教程之自定义属性用法详解

    自定义属性都存在于/value/attr.xml文件中,以如下格式存在。 代码如下: ”自定义属性名称”&gt; ”属性名称” format=”属性种类”/&gt; …… 对于自定义属性中的format的值及其含义如下: format属性值:reference 、...

    Android 自定义阴影效果详解及实例

    Android 自定义阴影效果详解及实例 Android5.X中,Google为其增加了两个属性 android:elevation=” ” 与 android:translationZ=” “,对应垂直方向上的高度变化。系统会自动增加阴影效果。 在TabLayout中增加...

    Android自定义控件属性详细介绍

    Android自定义控件属性详细介绍 1. reference:参考某一资源ID。   (1)属性定义:  (2)属性使用: &lt;ImageView android:layout_width = 42dip android:layout_height = 42dip

    Android控件架构与自定义控件详解(二)——自定义View

    在自定义View时,我们通常会去重写onDraw()方法来绘制View的显示内容。如果该View还需要使用wrap_content属性,那么还必须重写onMeasure()方法。另外,通过自定义attrs属性,还可以设置新的属性配置值。

    详解Android自定义控件属性

    控件时,难免要用到自定义属性,那怎么使用自定义属性呢? 在文件res/values/下新建attrs.xml属性文件,中定义我们所需要的属性。 &lt;?xml version=1.0 encoding=utf-8?&gt; &lt;resources&gt;&lt;!-- resource是跟标签...

    Android自定义控件之自定义属性(二)

    有关原理知识请参考Android自定义控件基本原理详解(一)这篇文章。  需求产生背景: 为何要引入自定义属性?当Android提供的原生属性不能满足实际的需求的时候,比如我们需要自定义圆形百分比半径大小、圆形背景...

    Android实现自定义的卫星式菜单(弧形菜单)详解

    在自定义View中读取布局文件中的自定义属性 (2)onMeasure 测量 child 即测量主按钮以及菜单项 (3)onLayout 布局 child 即布局主按钮以及菜单项 (4)设置主按钮的选择动画  a.为菜单项menuItem添加平移...

    Android中自定义进度条详解

    先来看看progressbar的属性: 代码如下: &lt;ProgressBar  android:id=”@+id/progressBar”  style=”?android:attr/progressBarStyleHorizontal”  android:layout_width=”match_parent”  

    自定义控件_深度解析自定义属性

    对应博客讲解地址:android自定义控件_深度解析自定义属性 http://blog.csdn.net/yezhuAndroid/article/details/79418570

    详解Android自定义控件属性TypedArray以及attrs

    大家也可以结合《理解Android中的自定义属性》这篇文章进行学习,后续一篇还有应用。 1、attrs文件编写 &lt;?xml version=1.0 encoding=utf-8?&gt; &lt;resources&gt; &lt;attr name=titleTextSize format=dimension&gt;...

    实例讲解Android自定义控件

    详解Android自定义控件属性 可以看到QQ上的ToolBar其实就是一个自定义的view,可以看到不同的界面就是简单地修改了文字而已,在第二张与第三张尤其的明显,我们就仿QQ的这个Toolbar设置一个自定义控件 在开始之前,...

    Android自定义控件之自定义组合控件(三)

    前两篇介绍了自定义控件的基础原理Android自定义控件基本原理详解(一)、Android自定义控件之自定义属性(二)。今天重点介绍一下如何通过自定义组合控件来提高布局的复用,降低开发成本,以及维护成本。 使用...

    Android自定义View详解

    很多的Android入门程序猿来说对于Android自定义View,可能都是比较恐惧的,但是这又是高手进阶的必经之路,所有准备在自定义View上面花一些功夫,多写一些文章。先总结下自定义View的步骤: 1、自定义View的属性 2、...

    Android使用属性动画如何自定义倒计时控件详解

    自Android 3.0版本开始,系统给我们提供了一种全新的动画模式,属性动画(property animation),它的功能非常强大,下面这篇文章主要给大家介绍了关于Android使用属性动画如何自定义倒计时控件的相关资料,需要的朋友...

Global site tag (gtag.js) - Google Analytics