>
in the Android system source code, most of the application's UI layout uses the preference layout structure, rather than the view layout structure we used when building the application in the simulator, for example, the layout in the setting module. Of course, there are exceptions to everything, and the view layout structure is used in the Fmradio application (perhaps the application is provided by the Marvel company, which is not possible if it is done by Google). In the final analysis, preference layout structure and view layout structure is essentially the same, preference the advantages of the layout interface controllability and efficiency and the simplicity of the stored value ( Each preferenpreferencece is stored under the corresponding Sharedpreference folder). Below, we compare the preference and the view under each sub-control, to their family elements in the macro has a better grasp of.
Single control:
Preference Controls Home View Control Home control meaning
Preference TextView text Box
checkpreference CheckBox Radio Box
edittextpreference edittext input text box
listpreference listview list box
ringtonepreference--Ringtones
In fact, there are many "unfinished" preference in the Android source system, and no PI interface is provided for them, such as Seekbarpreference,
Interested students can refer to the source code, the specific path is: Frameworks/base/core/java/preference.
To combine controls:
Preferencecategory: Similar to Linearlayou, relativelayout, used to combine a set of preference to make the layout more hierarchical.
Preferencescreen: The root node of all preference elements.
The way to display the preference layout structure is:
Let our activity inherit preferenceactivity and then pass in the OnCreate () method
Addpreferencesfromresource (r.xml.custom_preference) (our custom preference layout).
What, is it déjà vu? A demo will be used to give you a detailed description later.
Description of the generic XML attributes for the preference element:
android:key Span style= "FONT-FAMILY:SIMSUN; font-size:16px; " > : Each preference control's unique "ID", which uniquely represents this preference.
< Span style= "Color:rgb (255, 0, 0); > android:defaultvalue &NBSP;: Default value. For example, the default value for Checkpreference is "true", which is selected by default;
The default value for Edittextpreference can be "110".
< Span style= "Color:rgb (255, 0, 0); > android:enabled : Indicates whether the preference is a usable state.
< Span style= "Color:rgb (255, 0, 0); > android:title : The title that each preference displays on the Preferencescreen layout--Big title
< Span style= "Color:rgb (255, 0, 0); > android:summary : The caption that each preference appears on the Preferencescreen layout--a small caption (not available)
< Span style= "Color:rgb (255, 0, 0); > android:persistent : Indicates whether the value corresponding to the preference element is written to the Sharedpreferen file and, if true, indicates that the
is written
, otherwise, indicates that the value of the preference element is not written.
< Span style= "Color:rgb (255, 0, 0); > android:dependency : represents a preference (denoted by a) The available state depends on another preference (denoted by B). b available,
A is available; B is unavailable, then a is unavailable.
android:disabledependentsstate: Contrary to android:dependency . B is available, then A is not available and B is unavailable.
common methods include:
GetKey () setkey ( )
Getsummary () setsummary ()
GetText () SetText ()