要定制Android layout 中的 attributes关键是要明白android中命名空间定义如:

xmlns:android="http://schemas.android.com/apk/res/android

以RingtonePreference为例::

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/sound_settings"
    android:key="sound_settings"
    xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">

<com.android.settings.DefaultRingtonePreference
    android:key="ringtone"
    android:title="@string/ringtone_title"
    android:summary="@string/ringtone_summary"
    android:dialogTitle="@string/ringtone_title"
    android:persistent="false"
    android:ringtoneType="ringtone" />

在代码中::

public RingtonePreference(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

TypedArray a = context.obtainStyledAttributes(attrs,
            com.android.internal.R.styleable.RingtonePreference, defStyle, 0);
    mRingtoneType = a.getInt(com.android.internal.R.styleable.RingtonePreference_ringtoneType,
            RingtoneManager.TYPE_RINGTONE);
    mShowDefault = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showDefault,
            true);

mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent,
            true);
    a.recycle();
}

这里注意了ringtoneType的命名空间使用的是android, 而其容器中声明了两个命名空间android, settings
::

xmlns:android="http://schemas.android.com/apk/res/android
 xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"

何为命名空间呢?里面定义了各个类所用的属性的定义。 android这个命名空间就对应了/frameworks/base/core/res/res/values/attrs.xml文件中
定义的属性值;而settings这个命名空间就是Settings应用的res/values/attrs.xml或settings_attrs.xml文件中的属性.

如果我们查看frameworks/base/core/res/res/values/attrs.xml里面有对DefaultRingtonePreference的父类RingtonePreference的名字空间的定义:

::

<!-- Base attributes available to RingtonePreference. -->
<declare-styleable name="RingtonePreference">
    <!-- Which ringtone type(s) to show in the picker. -->
    <attr name="ringtoneType">
        <!-- Ringtones. -->
        <flag name="ringtone" value="1" />
        <!-- Notification sounds. -->
        <flag name="notification" value="2" />
        <!-- Alarm sounds. -->
        <flag name="alarm" value="4" />
        <!-- All available ringtone sounds. -->
        <flag name="all" value="7" />
    </attr>
    <!-- Whether to show an item for a default sound. -->
    <attr name="showDefault" format="boolean" />
    <!-- Whether to show an item for 'Silent'. -->
    <attr name="showSilent" format="boolean" />
</declare-styleable>

上例中declear-styleable中的属性name对应的类名,attr则是类中的属性.

 
 
 
 
 

xmlns:android作用以及自定义布局属性的更多相关文章

  1. android 开发 使用自定义布局实现标题栏复用(标题栏内容自定义:使用代码实现和xml布局自定义属性2种办法实现)

    在个人学习的情况下可能很少使用自定义布局去实现大量复用的情况下,但是在一个开发工作的环境下就会使用到大量复用的自定义控件. 实现思维: 1.写一个xml的布局,用于标题栏的样式,并且添加在标题栏中你想 ...

  2. Android xmlns 的作用及其自定义

    转自:http://blog.csdn.net/chuchu521/article/details/8052855 xmlns:Android="http://schemas.android ...

  3. android dialog使用自定义布局 设置窗体大小位置

    AlertDialog.Builder builder = new Builder(mContext); builder.setTitle("更新进度"); final Layou ...

  4. android代码中自定义布局

    转载地址:http://blog.csdn.net/luckyjda/article/details/8760214RelativeLayout rl = new RelativeLayout(thi ...

  5. Android之探究viewGroup自定义子属性参数的获取流程

    通常会疑惑,当使用不同的布局方式时,子view得布局属性就不太一样,比如当父布局是LinearLayout时,子view就能有效的使用它的一些布局属性如layout_weight.weightSum. ...

  6. 用ArrayAdapter来创建Spinner(自定义布局、默认布局、动态内容、静态内容)

             android:dropDownWidth 下拉列表宽度 android:dropDownHorizontalOffset 下拉列表距离左边的距离 android:dropDownV ...

  7. iOS-UICollectionView自定义布局

    UICollectionView自定义布局 转载: http://answerhuang.duapp.com/index.php/2013/11/20/custom_collection_view_l ...

  8. android自定义控件(3)-自定义当前按钮属性

    那么还是针对我们之前写的自定义控件:开关按钮为例来说,在之前的基础上,我们来看看有哪些属性是可以自定义的:按钮的背景图片,按钮的滑块图片,和按钮的状态(是开还是关),实际上都应该是可以在xml文件中直 ...

  9. xmlns:android="http://schemas.android.com/apk/res/android的作用是

    xmlns:android="http://schemas.android.com/apk/res/android的作用是 这个是xml的命名空间,有了他,你就可以alt+/作为提示,提示你 ...

随机推荐

  1. div垂直居中的方法(转)

    在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在这里我还要啰嗦两句,CSS中 ...

  2. http://bbs.phpcms.cn/thread-266337-1-1.html

    http://bbs.phpcms.cn/thread-266337-1-1.html utf8  改成 ANSI”

  3. [C# 基础知识系列]专题一:深入解析委托——C#中为什么要引入委托

    转自http://www.cnblogs.com/zhili/archive/2012/10/22/Delegate.html 引言: 对于一些刚接触C# 不久的朋友可能会对C#中一些基本特性理解的不 ...

  4. [JS] JavascriptHelp (转载)

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  5. Win7使用IIS通过域名访问本地程序(网页、css、js等)

    一.目的:在本地浏览器里面,输入www.abc.com 可以访问我们本地搭建的网页程序 二.好处:在本地模拟,真实的访问,另外可以设置一些二级域名,例如static.abc.com域名用来存储像图片, ...

  6. Undefined symbols for architecture armv7: "_OBJC_METACLASS_$_ _OBJC_CLASS_$_ ld: symbol(s) not found for architecture armv7错误

    Undefined symbols for architecture armv7:  "_OBJC_METACLASS_$_MWPhotoBrowser", referenced ...

  7. iOS 地图坐标系之间的转换WGS-84世界标准坐标、GCJ-02中国国测局(火星坐标,高德地图)、BD-09百度坐标系转换

    开发过程中遇到地图定位不准确,存在偏差.首先确认你获取到的坐标所在坐标系跟地图数据是不是相匹配的. 常用的地图SDK:高德地图使用的是GCJ-02(也就是火星坐标系),百度使用的是BD-09百度坐标系 ...

  8. UITableView编写可以添加,删除,移动的物品栏(一)

    效果图 :                                  点击编辑按钮:                      点击添加按钮                           ...

  9. 2014-11-9------- 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  10. 百度前端技术学院(IFE)2016春季学期总结

    今天(5月16日)作为第八个提交者提交了任务五十:RIA微型问卷管理平台 这样一个综合性的大任务,宣告我的IFE春季学期课程学习顺利完成.其实任务五十并不复杂,现在再让我来做,可能一周不到就写出来了, ...