在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類中來