java - How to make a simple settings page in android? -


i'm new in "android-app-dev"-scene , got 1 question:

how make clean looking settings page app?

there kind of headlines , kind of big buttons on can tab go new page.

i'm using android studio , know how create new page, class etc..

use preferenceactivity

sample code developer site:

public class preferencewithheaders extends preferenceactivity {     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          // add button header list.         if (hasheaders()) {             button button = new button(this);             button.settext("some action");             setlistfooter(button);         }     }      /**      * populate activity top-level headers.      */     @override     public void onbuildheaders(list<header> target) {         loadheadersfromresource(r.xml.preference_headers, target);     }      /**      * fragment shows preferences first header.      */     public static class prefs1fragment extends preferencefragment {         @override         public void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);              // make sure default values applied.  in real app,             // want in shared function used retrieve             // sharedpreferences wherever needed.             preferencemanager.setdefaultvalues(getactivity(),                     r.xml.advanced_preferences, false);              // load preferences xml resource             addpreferencesfromresource(r.xml.fragmented_preferences);         }     }      /**      * fragment contains second-level set of preference      * can tapping item in first preferences fragment.      */     public static class prefs1fragmentinner extends preferencefragment {         @override         public void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);              // can retrieve arguments preference xml.             log.i("args", "arguments: " + getarguments());              // load preferences xml resource             addpreferencesfromresource(r.xml.fragmented_preferences_inner);         }     }      /**      * fragment shows preferences second header.      */     public static class prefs2fragment extends preferencefragment {         @override         public void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);              // can retrieve arguments headers xml.             log.i("args", "arguments: " + getarguments());              // load preferences xml resource             addpreferencesfromresource(r.xml.preference_dependencies);         }     } } 

the preference_headers resource describes headers displayed , fragments associated them. is:

<header android:fragment="com.example.android.apis.preference.preferencewithheaders$prefs1fragment"         android:icon="@drawable/ic_settings_applications"         android:title="prefs 1"         android:summary="an example of preferences." />  <header android:fragment="com.example.android.apis.preference.preferencewithheaders$prefs2fragment"         android:icon="@drawable/ic_settings_display"         android:title="prefs 2"         android:summary="some other preferences can see.">     <!-- arbitrary key/value pairs can included header          arguments fragment. -->     <extra android:name="somekey" android:value="someheadervalue" /> </header>  <header android:icon="@drawable/ic_settings_display"         android:title="intent"         android:summary="launches intent.">     <intent android:action="android.intent.action.view"             android:data="http://www.android.com" /> </header> 

first header shown prefs1fragment, populates following xml resource:

<preferencecategory         android:title="@string/inline_preferences">      <checkboxpreference             android:key="checkbox_preference"             android:title="@string/title_checkbox_preference"             android:summary="@string/summary_checkbox_preference" />  </preferencecategory>  <preferencecategory         android:title="@string/dialog_based_preferences">      <edittextpreference             android:key="edittext_preference"             android:title="@string/title_edittext_preference"             android:summary="@string/summary_edittext_preference"             android:dialogtitle="@string/dialog_title_edittext_preference" />      <listpreference             android:key="list_preference"             android:title="@string/title_list_preference"             android:summary="@string/summary_list_preference"             android:entries="@array/entries_list_preference"             android:entryvalues="@array/entryvalues_list_preference"             android:dialogtitle="@string/dialog_title_list_preference" />  </preferencecategory>  <preferencecategory         android:title="@string/launch_preferences">      <!-- preferencescreen tag sends user new fragment of          preferences.  if running in large screen, can embedded          inside of overall preferences ui. -->     <preferencescreen             android:fragment="com.example.android.apis.preference.preferencewithheaders$prefs1fragmentinner"             android:title="@string/title_fragment_preference"             android:summary="@string/summary_fragment_preference">         <!-- arbitrary key/value pairs can included fragment arguments -->         <extra android:name="somekey" android:value="someprefvalue" />     </preferencescreen>      <!-- preferencescreen tag sends user different          activity, switching out of current preferences ui. -->     <preferencescreen             android:title="@string/title_intent_preference"             android:summary="@string/summary_intent_preference">          <intent android:action="android.intent.action.view"                 android:data="http://www.android.com" />      </preferencescreen>  </preferencecategory>  <preferencecategory         android:title="@string/preference_attributes">      <checkboxpreference             android:key="parent_checkbox_preference"             android:title="@string/title_parent_preference"             android:summary="@string/summary_parent_preference" />      <!-- visual style of child defined styled theme attribute. -->     <checkboxpreference             android:key="child_checkbox_preference"             android:dependency="parent_checkbox_preference"             android:layout="?android:attr/preferencelayoutchild"             android:title="@string/title_child_preference"             android:summary="@string/summary_child_preference" />  </preferencecategory> 

note xml resource contains preference screen holding fragment, prefs1fragmentinner implemented here. allows user traverse down hierarchy of preferences; pressing pop each fragment off stack return previous preferences.

see preferencefragment information on implementing fragments themselves.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -