8000 GitHub - XinyueZ/preference-demo: Shows how build preference on Android
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

XinyueZ/preference-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demo. Shows how build preference in Android

What

The preference or Setting etc, you know what I mean and what they can do in your Android App.

Official info

You can ignore this repository if you only want to read Google guides about preference programming, by clicking here.

Design concept

Prior to Android 3.0

A one sheet which almost all preference options, this design has been deprecated and replaced by the master/slave or headers/sheet pattern.

After Android 3.0

A master/slave or headers/sheet pattern, which means we list a summary headers on the main preference screen and user can do selection to any of them to operate on one sheet under header.

Programming

  1. A preference layout for one sheet or headers/sheet

    • preferenc 8000 e.xml, actually you can use any to name.

      A one sheet layout with PreferenceScreen

        <PreferenceScreen
                 xmlns:android="http://schemas.android.com/apk/res/android"
                 >
                 <CheckBoxPreference
                  android:key="preference_save_data"
                  android:title="Do you want to save data"
                  android:summary="Save your application data if you checked"
                  android:defaultValue="true"
                  />
      </PreferenceScreen>

      A one sheet layout with v7 PreferenceScreen

        <android.support.v7.preference.PreferenceScreen
                 xmlns:android="http://schemas.android.com/apk/res/android" >
       <android.support.v7.preference.CheckBoxPreference
                  android:key="preference_save_data"
                  android:title="Do you want to save data"
                  android:summary="Save your application data if you checked"
                  android:defaultValue="true"
                  />
      </android.support.v7.preference.PreferenceScreen>
      

      or A list of headers

      <preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >
       <header
       	android:title="Data save"
       	android:summary="Option of saving data of application."
       	android:fragment="com.example.SaveDataFragment">
       		<extra android:name="index" android:value="0"/>
           <extra android:name="header" android:value="preferences_save_data"/>
           <extra android:name="title" android:value="Save data"/>
         </header>
       <header
       	android:title="Delete cache"
       	android:summary="Clean application cache."
       	android:fragment="com.example.CleanCacheFragment">
       		<extra android:name="index" android:value="1"/>
           <extra android:name="header" android:value="preferences_clear_cache"/>
           <extra android:name="title" android:value="Clean cache"/>
         </header>
      </preference-headers>
    • Using attributes in xml are easy to understand, they are real easy just like what they are :) . One thing interesting is "android:fragment" which declares a fragment to display a Sheet when user select an option on master. I reiterate this in the late doc.

  2. Showing layout

  3. Standard or v7-support

As mentioned before there are two versions of preferences on Android, you can use platform native or some from v7-support, except PreferenceActivity (But you can create one AppCompatPreferenceActivity )almost all elements have v7,i.e android.support.v7.preference.PreferenceScreen and PreferenceScreen. What special are fragments like PreferenceFragment and PreferenceFragmentCompat which provide a little different features.

  1. PreferenceFragment and PreferenceFragmentCompat
  1. ActionBar or Toolbar


                      The MIT License (MIT)

                Copyright (c) 2016 Chris Xinyue Zhao

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.

About

Shows how build preference on Android

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
2EFB

Languages

0