Android provides an interface for convenient settings, so you have to say a thumbs up. The designers of basic functions are taken into account, which greatly facilitates developers. If there are no special requirements for the UI, these interfaces can fully meet your needs. Let's talk less about them and use cases directly.
If it is just a simple setting, you can layout it in an XML file. In addition, the designer provides a wide range of controls for developers to use. I personally feel pretty. Note that it is best to place the XML of the layout file in the res XML folder (create one by yourself). An error occurred when I put the XML file in layout. The layout file is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Preferencescreenxmlns: Android = "http://schemas.android.com/apk/res/android"> <preferencecategory Android: Title = "Q & A Settings"> <listpreference Android: Key = "listpreference" Android: title = "number of questions and answers displayed each time" Android: Summary = "" Android: defaultvalue = "20" Android: dialogtitle = "select the number of questions and answers to be displayed" Android: entries = "@ array/entries_list_preference" Android: entryvalues = "@ array/templates"/> </preferencecategory> <preferencecategory Android: Title = "Advanced Settings"> <checkboxpreference Android: key = "push" Android: Title = "Push accepted" Android: summaryon = "enable" Android: summaryoff = "Disable" Android: defaultvalue = "true"/> <checkboxpreference Android: key = "hdpi" Android: Title = "select high-resolution images" Android: summaryon = "high-resolution images" Android: summaryoff = "low-resolution images" Android: defaultvalue = "true"/> </preferencecategory> </preferencescreen>
If you want to use the set value, you can call it as follows:
Sharedpreferences SHP = preferencemanager. getdefasharsharedpreferences (this); Boolean apply_wifichecked = SHP. getboolean ("apply_wifi", false );
For more details about the controls on the settings page, see
Preference usage.
It is easy to learn, and it is inevitable that there will be omissions and errors. please correct me ~