Android setting is usually written using preferenceactivity.
We are creating the layout file:
<Preferencescreen xmlns: Android = "http://schemas.android.com/apk/res/android"> <preferencecategory Android: Title = "general settings" Android: Key = "set_local"> <checkboxpreference Android: Key = "new_message_policy" Android: title = "New Message notification" Android: defaultvalue = "true" Android: Summary = "do you need to notify me when receiving a new message"/> <ringtonepreference Android: Layout = "? Android: ATTR/preferencelayoutchild "Android: dependency =" new_message_policy "Android: Key =" account_ringtone "Android: Title =" ringtone "Android: ringtonetype =" notification "Android: defaultvalue = "content: // settings/system/notification_sound"/> <checkboxpreference Android: Layout = "? Android: ATTR/preferencelayoutchild "Android: dependency =" new_message_policy "Android: Key =" account_vibrate "Android: defaultvalue =" false "Android: title = "vibration"/> </preferencecategory> <preferencecategory Android: Title = "personal Settings" Android: Key = "personal_local"> <preference Android: Key = "clear_cache" Android: summary = "click to clear the application cache" Android: Title = "Clear cache" defaultvalue = "false"> </preference> <checkboxpreference Android: Key = "save_setting" Android: summary = "Remember personal settings next time" Android: Title = "Save personal Settings" Android: defaultvalue = "true"> </checkboxpreference> <edittextpreference Android: key = "edit_text" Android: Title = "edit" Android: Summary = "edittextpreference"> </edittextpreference> <switchpreference Android: Key = "Switch" Android: summary = "switchpreference"> </switchpreference> <listpreference Android: Key = "list" Android: Summary = "listpreference" Android: entries = "@ array/entry" Android: entryvalues = "@ array/entry_value" Android: Title = "listtitle"> </listpreference> <multiselectlistpreference Android: Summary = "multiselectlistpreference" Android: Key = "mutiselect" Android: entries = "@ array/entry" Android: entryvalues = "@ array/entry_value" Android: Title = "mutititle"/> </preferencecategory> </preferencescreen>
The class code is as follows:
Public class settings extends preferenceactivity {@ overrideprotected void oncreate (bundle savedinstancestate) {// Add custom titlefinal Boolean iscustom = requestwindowfeature (window. feature_custom_title); super. oncreate (savedinstancestate); If (iscustom) {getwindow (). setfeatureint (window. feature_custom_title, R. layout. title_list);} textview title_text = (textview) findviewbyid (R. id. title_text); title_text.settext ("Settings"); button back = (button) findviewbyid (R. id. back); Back. setvisibility (view. visible); Back. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {finish () ;}}); addpreferencesfromresource (R. XML. seting_preferences );}}
Define themes and set theme of the activity as follows:
<Style name = "apptheme" parent = "appbasetheme"> <! -- All mizmizations that are not specific to a special API-level can go here. --> <! -- Avoid repeated title settings --> <item name = "Android: windowactionbar"> false </item> <! -- Set the Title Bar Width --> <item name = "Android: windowtitlesize"> 60dp </item> // titlebar height <! -- <Item name = "Android: windowtitlebackgroundstyle"> @ style/customwindowtitlebackground </item> --> </style>
This can be done when the value is set:
Sharedpreferences SHP = preferencemanager. getdefasharsharedpreferences (this); string S = SHP. getstring ("list", null); // This is the listpreferencetextview listdata = (textview) findviewbyid (R. id. listdata); listdata. settext (s); hashset set = (hashset) SHP. getstringset ("mutiselect", null); // This is the iterator that obtains the value of multiselectlistpreference <string> it = set. iterator (); string content = ""; while (it. hasnext () {content + = it. next () + ",";} textview muti_select_data = (textview) findviewbyid (R. id. muti_select_data); muti_select_data.settext (content );
Yes: