Free Android app covering all aspects of addiction, including prevention and treatment

Preference Settings

Preference Settings

Android Preference Settings icon

Preference Settings allow the user to select basic settings for an app. It’s a way of customising the app to suite the user.

This tutorial will show you how you can create your own custom Preference Settings for your apps.

We’ll be using fragments and Headers so this tutorial is suitable for apps developed for devices running Android 3.0 and up.

There are four parts to the Preference Framework. We’ll cover all of them:

  • Preference Screen Layout –the xml file defining your settings items
  • Preference Activity and Fragment – these host the Preference screens. The activity hosts the fragment and the fragment hosts the Preference Screen, displaying your settings
  • Preference Headers – these are lists of subscreens. An xml file defines the Preference Fragments used for the Headers subscreens
  • Shared Preference Change Listener – listens for any changes in the Shared Preference values

Each Preference appears as an item in a list. The user is able to modify these preference settings.