xml属性解析

来源:互联网 发布:淘宝助理4.6版下载 编辑:程序博客网 时间:2024/04/27 08:42

在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类中来


原创粉丝点击