Usually the app will have a setup interface, as follows:
The usual practice is to define the layout yourself, and 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 have 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 directory and create a file named Main_preference (that is, the resource file referenced in the code).3. Write the resource file. The corresponding resource file for the Setup interface is as follows:
<?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 headings "> <listpreference android:defaultvalue=" @string/defaultvalues "android:dialogtitle=" to The box title "android:entries=" @array/entries "android:entryvalues=" @array/entriesvalue "Android: key= "Mylistpreference" android:summary= "caption description" android:title= "small title"/> <checkboxpreferenc E android:key= "Doubi" android:summaryoff= "tease mode Off" android:summaryon= "tease mode on" a Ndroid:title= "tease mode" > </CheckBoxPreference> </PreferenceCategory> <preferencecategory android:summary= "Group 2" android:title= "Group 2 title" > <switchpreference android:key= "Fly" Android:summaryoff= "Airplane mode is off" Android:summaryon= "Airplane mode turned on" android:switchtextoff= "Off" android:switchtexton= "on" Android:title= "Airplane mode" > </SwitchPreference> <edittextpreference android:defaultvalue= "Zhangsan" android:dialogtitle= "edit name" android:key= "name" android:summary= "Edit Your Name" android:title= "edit" > </EditTextPreference> </PreferenceCategory></PreferenceScreen>
it refers to the relevant content of String.xml:
<?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> Little 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 in the data/data/package name/shared_prefs directory, as in Sharepreferences.