Usually the app will have a setup interface, such as the following:
The usual practice is to customize the layout, then add the response function to the code and save the results to sharedpreferences. Android provides us with a preferenceactivity to simplify the development setup interface.
You just need to do this:1. Create a class to inherit preferenceactivity and import the Setup interface layout:
Package Com.example.preferenceactivitydemo1;import Android.os.bundle;import android.preference.PreferenceActivity ;p ublic class Mainactivity extends preferenceactivity{@SuppressWarnings ("deprecation") @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Addpreferencesfromresource (R.xml.main_ preference);}}
2. Add the XML folder under the Res folder and create a file named Main_preference (that is, the resource file referenced in the code).
3. Write the resource file. Set the appropriate resource file for the interface such as the following:
<?xml version= "1.0" encoding= "Utf-8"?><preferencescreen xmlns:android= "http://schemas.android.com/apk/res/android" android:title= "title" > < Preferencecategory android:summary= "Grouping 1" android:title= "Grouping 1 Titles" > <listpreference and Roid:defaultvalue= "@string/defaultvalues" android:dialogtitle= "dialog box title" Android:entries= "@array/entrie S "android:entryvalues=" @array/entriesvalue "android:key=" Mylistpreference "Android:summa Ry= "caption description" android:title= "small title"/> <checkboxpreference android:key= "Doubi" and Roid:summaryoff= "tease mode Off" android:summaryon= "tease mode on" android:title= "tease mode" > </checkboxpr eference> </PreferenceCategory> <preferencecategory android:summary= "Group 2" android:title= "min Group 2 title "> <switchpreference android:key=" Fly "android:summaryoff=" off airplane Mode "and Roid:summaryon= "Airplane mode is turned on" android:switchtextoff= "Off" android:switchtexton= "on" android:title= "Airplane mode" > </s witchpreference> <edittextpreference android:defaultvalue= "Zhangsan" android:dialogtitl E= "Edit name" android:key= "name" android:summary= "Edit Your Name" android:title= "edit" > </ Edittextpreference> </PreferenceCategory></PreferenceScreen>
the relevant contents of String.xml are quoted as follows:
<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "app_name" >PreferenceActivityDemo1</string> <string Name= "Action_settings" >Settings</string> <string name= "Hello_world" >hello world!</string ><string-array name= "Entries" > <item> small apple </item> <item> small Banana </item> <item> Small Watermelon </item></string-array><string-array name= "Entriesvalue" > <item>apple </item> <item>banana</item> <item>watermelon</item></string-array> <string name= "Defaultvalues" >apple</string></resources>
Well, it's so simple ~
All results are saved to the package name _preferences.xml under the data/data/Package name/shared_prefs folder, as in Sharepreferences.
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
"Android Notes" high-speed development Setup Interface-----preferenceactivity