How to Create Setting Screen in Android ?

         There are millions of app on Google Play Store and having User settings in that. But how to create Setting Screen and change when user change it. yes if you want some Settings user can change in your app then you may require setting screen in your application like in Games you can see Sound setting or Vibration etc. Its Good if you provide Settings or preference to the user so they can change it as per their requirement or use.

In this Tutorial i am gone use following concepts
  1. Preference Screen
  2. Preference
  3. Edit Text Preference.

First Create New xml File in res\xml folder. make sure xml is of preference type.



In above Code you can see I have Used Two types of Preferences Simple Preferences that you can use to open another sub settings or activity and Edit Text Preference to get some detail from user using edit text. Now Create New Class File And Give Same Name As Above Xml file. i have Used Pref as my Class name. In preference you have to use Three Properties.

  • Key is a unique key(id) like You give Id to the Object (Button or Text View) .
  • Title - What you want to display as title in Setting Screen.
  • Summary - is brief idea about the Setting.
Now Copy Below Code in your class file.
package com.androprogrammer.app2;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class Pref extends PreferenceActivity {

 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub


Screen Shots

  This Is how It Looks. I have Used Only Two kinds of preferences but you can use n numbers of it. It is the simplest and Nice way to display User Settings in Android Application.Preferences having one benefit and is that it will directly store in android. you don't have to write code to store it. before running your application make sure you have registered it in manifest file. because we have created both file separately xml and class file.

if you like above post or any other post on this blog share it on your Social Circle to help us. 


Post a comment