xml属性解析

在Android项目中各种控件的xml属性大家都用过,例如android:key 可是这些属性在哪里可以找到?在源码中frameworks/base/core/res/res/values/attrs.xml中都可以找到,以Preference为例

<!-- Base attributes available to Preference. -->
    <declare-styleable name="Preference">
        <!-- The key to store the Preference value. -->
        <attr name="key" format="string" />
        <!-- The title for the Preference in a PreferenceActivity screen. -->
        <attr name="title" />
        <!-- The summary for the Preference in a PreferenceActivity screen. -->
        <attr name="summary" format="string" />
        <!-- The order for the Preference (lower values are to be ordered first). If this is not
             specified, the default orderin will be alphabetic. -->
        <attr name="order" format="integer" />
        <!-- The layout for the Preference in a PreferenceActivity screen. This should
             rarely need to be changed, look at widgetLayout instead. -->
        <attr name="layout" />
        <!-- The layout for the controllable widget portion of a Preference. This is inflated
             into the layout for a Preference and should be used more frequently than
             the layout attribute. For example, a checkbox preference would specify
             a custom layout (consisting of just the CheckBox) here. -->
        <attr name="widgetLayout" format="reference" />
        <!-- Whether the Preference is enabled. -->
        <attr name="enabled" />
        <!-- Whether the Preference is selectable. -->
        <attr name="selectable" format="boolean" />
        <!-- The key of another Preference that this Preference will depend on.  If the other
             Preference is not set or is off, this Preference will be disabled. -->
        <attr name="dependency" format="string" />
        <!-- Whether the Preference stores its value to the shared preferences. -->
        <attr name="persistent" />
        <!-- The default value for the preference, which will be set either if persistence
             is off or persistence is on and the preference is not found in the persistent
             storage.  -->
        <attr name="defaultValue" format="string|boolean|integer|reference|float" />
        <!-- Whether the view of this Preference should be disabled when
             this Preference is disabled. -->
        <attr name="shouldDisableView" format="boolean" />
    </declare-styleable>
如果想在xml中对这些属性进行设置代码如下

 <Preference android:key="sn" 
   		android:textSize="17sp"
        android:title="@string/status_sn"
        android:summary="@string/device_info_not_available"
        android:persistent="false" />
  
                 

而对这些属性的解析会定位到android.preference.Preference类中来


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值