We often see Settings screen in many android apps through which you can configure the app preferences on your choice. For example you wanna change the notification sound or turn off notification messages from the app settings.

Normally people manually develop their own UI for settings and manage the values in shared preferences, not awaring the fact that android do provide APIs specific to Settings Preferences to achieve the same in a robust way. In this article we are going to learn how to implement the settings screen considering the various combinations of settings items.


The preference API consists of multiple widget like EditTextPreference, CheckBoxPreference, ListPreference and few more to achieve the most used settings. You can also implement the advanced options like ringtone selection, sync options etc.,

1. Settings with Preference Headers

Preference Headers displays only the settings groups (headers) on the first screen and selecting a group displays the sublist. The preference headers usually used for tablets or if there are multiple settings with nested options. The benefit of using headers is, the screen will be automatically divided into two panels when the app is running on tablet.

Below is the example of Youtube app settings with preference headers.


1.1 Adding Settings Activity from Android Studio Templates

The Settings Activity can be added from Android Studio templates directly with all the necessary code added to activity.

In Android Studio go to File ⇒ Activity ⇒ Settings Activity. This creates necessary preferences xml resources under res ⇒ xml directory.


If you launch the Settings Activity, you will see the output as below.


The Problem:

The problem with creating settings from a template is, there is no guarantee that the auto generated code always meets your requirements. With current version of Android Studio I have (v2.3), the settings activity is generated with all headers as default screen which is not necessary in my app. Even it takes more effort to customize the auto generated code. The best way is, create everything manually so that you will have more control over the output you are expecting.

So let’s start by creating new project in Android Studio and see how to add the settings manually.

2. Creating New Project

1. Create a new project in Android Studio from File ⇒ New Project and fill the project details. I gave project name as Preferences and package name as info.androidhive.settings.

2. Open strings.xml and add the below string values.

    <string name="app_name">Preferences</string>
    <string name="action_settings">Settings</string>
    <string name="title_activity_settings">Settings</string>

    <string name="pref_title_ringtone">Ringtone</string>
    <string name="pref_ringtone_silent">Silent</string>

    <string name="default_gallery_storage">My Videos</string>
    <string name="title_auto_upload">Auto upload</string>
    <string name="summary_upload_over_wifi">Upload the videos when wifi is available</string>
    <string name="title_upload_quality">Upload Quality</string>
    <string name="summary_upload_video_quality">Specify video quality for uploads</string>
    <string name="pref_title_notifications">Notifications</string>
    <string name="summary_choose_ringtone">Choose notification sound</string>
    <string name="pref_header_about">About</string>
    <string name="summary_about">We are a team of like-minded people, specialized in development of Android App Development creating new trends across the app space. Glad to Help in anyway!</string>
    <string name="app_version">3.5</string>
    <string name="summary_support">Got any queries? We are happy to help!</string>
    <string name="title_send_feedback">Send Feedback</string>
    <string name="title_faq">FAQ</string>
    <string name="summary_faq">View frequently asked questions</string>
    <string name="url_faq">https://www.androidhive.info/privacy-policy/</string>
    <string name="privacy_policy">Privacy Policy</string>
    <string name="url_privacy">https://www.androidhive.info/privacy-policy/</string>
    <string name="title_terms">Terms &amp; Conditions</string>
    <string name="url_terms">https://www.androidhive.info/terms-of-service/</string>
    <string name="title_version">Version</string>
    <string name="choose_email_client">Choose email client</string>
    <string name="title_gallery_storage">Default Storage</string>
    <string name="title_new_notification_sound">New message notification</string>
    <string name="title_vibrate">Vibrate</string>
    <string name="summary_vibrate">Vibrate on new notification</string>
    <string name="key_upload_over_wifi">key_upload_over_wifi</string>
    <string name="key_gallery_name">key_gallery_name</string>
    <string name="key_upload_quality">key_upload_quality</string>
    <string name="notifications_new_message">notifications_new_message</string>
    <string name="key_notifications_new_message_ringtone">key_notifications_new_message_ringtone</string>
    <string name="key_vibrate">key_vibrate</string>
    <string name="key_send_feedback">key_send_feedback</string>

3. Create new xml named arrays.xml under res ⇒ arrays.xml and add the below arrays. These arrays contains values necessary for ListPrefereces.

<?xml version="1.0" encoding="utf-8"?>
    <string-array name="pref_upload_quality_entries">
    <string-array name="pref_upload_quality_values">

4. Create an xml named pref_main.xml under res ⇒ xml. If the xml directory is not existed, create a new folder with the name.

The preferences screen can be designed with an xml just like the layout xml we use for a view, except it will reside in xml directory. We have used below elements in the current settings screen.

> EditTextPreference – Used to collect text input from user

> CheckBoxPreference – Displays a checkbox to toggle a setting

> ListPreference – Displays a diglog with list of options to choose

> SwitchPreference – Turn on/off a setting

> RingtonePreference – Launches devices’s ringtone list in which user can select preferred sound

> Preference with an Intent action android.intent.action.VIEW – to open external browser navigating to an url

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory android:title="General">
            android:title="@string/title_gallery_storage" />

            android:title="@string/title_auto_upload" />

            android:title="@string/title_upload_quality" />


    <PreferenceCategory android:title="@string/pref_title_notifications">

            android:title="@string/title_new_notification_sound" />

            android:title="@string/pref_title_ringtone" />

            android:title="@string/title_vibrate" />

    <PreferenceCategory android:title="@string/pref_header_about">

            android:summary="@string/summary_about" />

            android:title="@string/title_version" />

            android:title="@string/title_send_feedback" />

        <!-- preference opens url in browser -->
                android:data="@string/url_faq" />

        <Preference android:title="@string/privacy_policy">
                android:data="@string/url_privacy" />

        <Preference android:title="@string/title_terms">
                android:data="@string/url_terms" />

5. Create a class named AppCompatPreferenceActivity.java and add the below code. This class provides compatibility across all the devices and versions.

import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

 * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
 * to be used with AppCompat.
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {

    private AppCompatDelegate mDelegate;

    protected void onCreate(Bundle savedInstanceState) {

    protected void onPostCreate(Bundle savedInstanceState) {

    public ActionBar getSupportActionBar() {
        return getDelegate().getSupportActionBar();

    public void setSupportActionBar(@Nullable Toolbar toolbar) {

    public MenuInflater getMenuInflater() {
        return getDelegate().getMenuInflater();

    public void setContentView(@LayoutRes int layoutResID) {

    public void setContentView(View view) {

    public void setContentView(View view, ViewGroup.LayoutParams params) {
        getDelegate().setContentView(view, params);

    public void addContentView(View view, ViewGroup.LayoutParams params) {
        getDelegate().addContentView(view, params);

    protected void onPostResume() {

    protected void onTitleChanged(CharSequence title, int color) {
        super.onTitleChanged(title, color);

    public void onConfigurationChanged(Configuration newConfig) {

    protected void onStop() {

    protected void onDestroy() {

    public void invalidateOptionsMenu() {

    private AppCompatDelegate getDelegate() {
        if (mDelegate == null) {
            mDelegate = AppCompatDelegate.create(this, null);
        return mDelegate;

6. Create new activity named SettingsActivity from File ⇒ New ⇒ Activity ⇒ Empty Activity and do the below changes.

> Extend this class from AppCompatPreferenceActivity that we have created in the above step.

> Remove setContentView() and load the MainPreferenceFragment() fragment.

> MainPreferenceFragment() contains all the necessary methods to inflate the settings xml, provides callbacks when the settings are changed.

package info.androidhive.settings;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.RingtonePreference;
import android.text.TextUtils;
import android.view.MenuItem;

public class SettingsPrefActivity extends AppCompatPreferenceActivity {
    private static final String TAG = SettingsPrefActivity.class.getSimpleName();

    protected void onCreate(Bundle savedInstanceState) {

        // load settings fragment
        getFragmentManager().beginTransaction().replace(android.R.id.content, new MainPreferenceFragment()).commit();

    public static class MainPreferenceFragment extends PreferenceFragment {
        public void onCreate(final Bundle savedInstanceState) {

            // gallery EditText change listener

            // notification preference change listener

            // feedback preference click listener
            Preference myPref = findPreference(getString(R.string.key_send_feedback));
            myPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                public boolean onPreferenceClick(Preference preference) {
                    return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
        return super.onOptionsItemSelected(item);

    private static void bindPreferenceSummaryToValue(Preference preference) {

                        .getString(preference.getKey(), ""));

     * A preference value change listener that updates the preference's summary
     * to reflect its new value.
    private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String stringValue = newValue.toString();

            if (preference instanceof ListPreference) {
                // For list preferences, look up the correct display value in
                // the preference's 'entries' list.
                ListPreference listPreference = (ListPreference) preference;
                int index = listPreference.findIndexOfValue(stringValue);

                // Set the summary to reflect the new value.
                        index >= 0
                                ? listPreference.getEntries()[index]
                                : null);

            } else if (preference instanceof RingtonePreference) {
                // For ringtone preferences, look up the correct display value
                // using RingtoneManager.
                if (TextUtils.isEmpty(stringValue)) {
                    // Empty values correspond to 'silent' (no ringtone).

                } else {
                    Ringtone ringtone = RingtoneManager.getRingtone(
                            preference.getContext(), Uri.parse(stringValue));

                    if (ringtone == null) {
                        // Clear the summary if there was a lookup error.
                    } else {
                        // Set the summary to reflect the new ringtone display
                        // name.
                        String name = ringtone.getTitle(preference.getContext());

            } else if (preference instanceof EditTextPreference) {
                if (preference.getKey().equals("key_gallery_name")) {
                    // update the changed gallery name to summary filed
            } else {
            return true;

     * Email client intent to send support mail
     * Appends the necessary device information to email body
     * useful when providing support
    public static void sendFeedback(Context context) {
        String body = null;
        try {
            body = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
            body = "\n\n-----------------------------\nPlease don't remove this information\n Device OS: Android \n Device OS version: " +
                    Build.VERSION.RELEASE + "\n App Version: " + body + "\n Device Brand: " + Build.BRAND +
                    "\n Device Model: " + Build.MODEL + "\n Device Manufacturer: " + Build.MANUFACTURER;
        } catch (PackageManager.NameNotFoundException e) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"contact@androidhive.info"});
        intent.putExtra(Intent.EXTRA_SUBJECT, "Query from android app");
        intent.putExtra(Intent.EXTRA_TEXT, body);
        context.startActivity(Intent.createChooser(intent, context.getString(R.string.choose_email_client)));

Now we have the settings screen implemented. We just need to add a menu item in the toolbar’s overflow menu to launch the settings.

7. Open menu_main.xml under res ⇒ menu and add the settings menu item.

8. Open MainActivity.java and launch SettingsActivity when the settings is selected from overflow menu.

package info.androidhive.settings;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            // launch settings activity
            startActivity(new Intent(MainActivity.this, SettingsPrefActivity.class));
            return true;

        return super.onOptionsItemSelected(item);

Run the project and open the settings from toolbar’s menu item.


I hope this article explained most of the concepts regarding preference settings. If you still have any queries, please do let me know in the comments section below.

Happy Coding 😀


Settings developer guide

Material guidelines for Settings

Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk: ravi@androidhive.info
  • Michael

    Thank you so much Ravi, your tutorials literarily makes my dev life easier

  • Thank you so much for the tutorial. You have covered lot of implementation difficulties developers face in this tutorial.

  • Abdul Rehman

    plz sir make a tutorial of android app to make a recycle view or an array items app that when we click so a next activity open with its full image and description like a food recipe app or image gallery app with its admin panel or cms thanks

  • Yoav Sabag

    Get help from androidhive I have successfully create my new app

  • Tigani

    Thanks Ravi

  • Kang Prayit

    Nice tutorial ravi,
    thanks a lot
    out of thread question, i wonder how do you create the video mirroring the app running on the phone?

    • I records my mobile screen and place it on a nexus skin while editing.

      • Which software u use for editing videos?

        • Didier Serge Boka

          DU Recorder

      • Rick

        Hey @ravi8x:disqus do you have any tutorial on writing test cases for android app?
        Test Cases like JUnit or Mockito, or Instrumentation.
        Or do you have any plan to do a tutorial on writing test cases?
        If you have some source codes where you did these test cases as well then can you post it here or send me at gladiatorrick@gmail.com ?

  • sanjay

    How to replace the value received from EditTextPreference or ListPreference or toogle to the variable of another activity to actually implement the changes made in settings activity. Another question is:- i have toogle option in settings to toogle dark and light theme. How do i implement this theme feature?
    Thanks in advance!

    • Mohamed Ghouse

      Extend your base theme from Theme.AppCompat.Night
      Get the preference and set the theme based on it.
      Check out the article below on how to set the theme

      Also I would recommend three option in user setting like Light, Dark and Auto

      • Thanks Mohamed.

        • Mohamed Ghouse

          You are welcome mate!! BTW thanks for the awesome tutorials. I hope you would do one explaining the basics of MVVM or MVP architecture.

  • Shivam Goyal

    i want to add 3 dots option in my app, how will i get it
    please help

    • paijojr

      1. create menu folder under res folder, right click in res folder – new – android resource directory – resource type choose menu – ok
      2. create menu_main.xml under menu folder, look at point 7 above
      3. add onCreateOptionsMenu(Menu menu) and onOptionsItemSelected(MenuItem item) inside mainactivity, look at point 8 above


      • Shivam Goyal

        where are these 7 and 8 points???

      • paijojr

        read tutorial in this url, scroll above please then find point 7 and 8

  • paijojr

    Good tutorial Ravi
    I have problem with actionBar error java.lang.NullPointerException in line getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    If I was deleted getSupportActionBar().setDisplayHomeAsUpEnabled(true); SettingsActivity can launch but without Toolbar, how to solved that?
    Thanks in advance!

    • Mohamed Ghouse

      Make sure you are not extending your theme from theme.appcompat.light.noactionbar or any other noactionbar variants for your settings activity.

      If you want to use your custom toolbar then you have to create a layout resource file with toolbar and FrameLayout to attach Preference fragment.

      • paijojr

        thanks Mohamed

        I was try to remove extending noactionbar in manifest and on styles.xml but there’s still error NPE. I am using Theme.AppCompat.Light.DarkActionBar

        Do you have example for custom toolbar?Thanks in advance!

        • Mohamed Ghouse

          Hi paijojr,

          Theme.AppCompat.Light.DarkActionBar should have fixed it, can you post your error logs?

          Also try this one and see it fixes the error

          Then in your actvity

          protected void onCreate(Bundle savedInstanceState) {
          new SettingsFragment()).commit();

          Setting Fragment Should stay the same

  • Jyoti Sharma

    Hello sir
    i want to add pagination like websites in my app to display history. How will i get it. Please help


    • Jyoti Sharma

      is it possible?

      • It is. How the content is fetched from server? Is it via REST API?

        • Jyoti Sharma


          • Jyoti Sharma

            Eagerly waiting for your reply

  • Syukur Zay

    Amazing Tutorial Ravi..
    I want to ask how to disable and enable internet connection, Preferences Settings Screen?

  • Kondwani Z Msiska

    Am having a problem I cant load the actionbar on the SettingsActivity

    • Whats the theme set to SettingsActivity in AndroidManifest?

      • subm

        I am currently using a custom theme and face the same problem.

  • subm

    Hey Ravi, I have problem on ‘extends AppCompatPreferenceActivity’ in SettingsActivity. Any clue?

  • Ayushi Mundra

    Hi ,
    I have chechBoxPrefernce within PrferenceCategory .
    My requirement is to make check box true always at backend and that prefernce should be invisible from screen in mobile . How to make Preference category invisible from front end .

    Suggest me .

    • Mohd Shah Nawaz

      For that you don’t need to have chechBoxPrefernce and make it visible. You can achieve the same by
      the following…

      // Shared Preferences
      SharedPreferences pref;

      // Editor for Shared preferences
      SharedPreferences.Editor editor;
      pref = _context.getSharedPreferences(“mySharedPrefs”, PRIVATE_MODE);
      editor = pref.edit();
      editor.putBoolean(“key_checkbox”, true);
      // commit changes

  • Egor Shyker

    Great tutorial, but backarrow in toolbar in settings with headers doesnt work. Please help me. https://uploads.disquscdn.com/images/f4105e95359300d1937b787e9edea797866540029a9ce2d513bbff332a3df0f3.png

    • You need to mention parent activity in your AndroidManifest.xml or override onOptionsItemSelected in your activity.

      Add the below to your activity

      public boolean onOptionsItemSelected(MenuItem item) {

      if (item.getItemId() == android.R.id.home) {
      return super.onOptionsItemSelected(item);

  • Dana Zhu

    Quick Question: does this not work for Android builds that are higher than Honeycomb? I made a settings activity, but noticed @TargetApi(Build.VERSION_CODES.HONEYCOMB) in my code.


  • ashu

    how can i get edittext value in a string in mainActivity?

  • ashu

    hello new to android development.. someone please tell me how can i get data so i can use it in my services and main activity.


    get value from above to a string called mqtthost.

  • Paramvir Singh

    HI ravi would you please write some article regarding MVC pattern

    • gautam kumar

      Yes please make one post on mvc , i cannot find any simple explanation in web so i am not able to understand . If possible use dagger, butterknife and rxjava. Hope you will make soon . Thank you.

      • I have prepared a Draft but explaining it in easier way is a bit difficult because of MVP structure. I’ll write it soon.

  • subm

    Sir is it possible to make a notification by toggle on the switchpreference??
    If yes, how??

    • Keep a boolean value in preference settings. Before showing the notification using notification method, check the boolean value and show the notification. Your device will always receives the notifications, but will be visible to user only when the option is enabled in preference settings.

      • subm

        thanks for your answer. I’ve tried it, but the showNotification() is not a static method, it could not be referenced in MainPreferenceFragment.

        • It has to be called from notification receiver classes. You have to check your preference value in that class instead in main activity.

  • sk panchal

    when i extend appcompatpreferencesActivity this show me error unsolvable reference

    what i doing wrong.

  • Jarosław

    setSummary() not accept string value for ListPreference.

  • Muhammad Haroon Dar

    Please Share Us Web Service Tutorials

  • Parneet Singh

    Sir! Please Tell me how to set offline resources for the images.Answer would be apperciated.Please tell me i
    didn’t want online content i only want images from offline assets folder please tell me the changes that i have to do in you current code(Gallery App with Glide)

  • jas

    The notification headers are coming as single line hence ending with 2 dots(..). How to make the headers multiline. ?

  • Rob Shish

    Hi, how did you create that sliding animation when you click on the BACK and Settings button? The code is not presented in your above provided code. Thank you.

    • The arrow was shown using getSupportActionBar().setDisplayHomeAsUpEnabled(true);. You can identify the click of the arrow by overriding onOptionsItemSelected method.

      public boolean onOptionsItemSelected(MenuItem item) {
      if (item.getItemId() == android.R.id.home) {
      // take your action here
      return true;
      return super.onOptionsItemSelected(item);

      • Rob Shish

        I know all that.. I used the below code for when you click on Settings button and the following code does a specific animation:

        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

        Do I also place code for clicking BACK arrow animation, in the same “onOptionsItemsSelected(MenuItem item)” code?

        • Yes, you can.

          • Rob Shish

            Ok, I got it figured out now, thank you. Last question. I created a fragmented tab layout with various tabs. When I click from Settings the <– back button, it always takes me back to the specific tab that I came from.

            Which code in your code above is the one that saves and remembers the specific tab I was on when I clicked on Settings?

            For example if I was on my "Groups" tab and clicked on settings then when I clicked BACK out of settings, it'd take me back to "Groups" tab specifically and not the default 1st tab in TabLayout.

          • That is the default behavior of Tabs.

          • Rob Shish

            When I’m on my 2nd tab for example and click on the Floating Action Bar then when I click back in the Floating Action Bar pg, it takes me back to the default 1st tab and not to the 2nd tab where I was.

            That’s why I’m curious which code it was to take me back to specific tab instead of the default 1st tab.

          • ayaz khalid

            i still dont understand the sliding animation,is that view pager default animation?

          • Yes

  • Anele

    Attempt to invoke virtual method ‘void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)’ on a null object reference

    • Anele

      kindly help

      • You need to have Toolbar / Appbar in your activity. Either add it in your activity layout or add it via theme in manifest file.

        • Anele

          thank you i am trying to add the settings preference on a navigation drawer facing some challenges

  • Jobin Jeeji

    hello ravi sir iam a fan of yours thanks for all the tutorials….can you please post a tutorial about data binding?

  • Arthur Grangeiro

    First of all your tutorial was the best I found so far, it helped me a lot. Thank you. Secondly, I was testing your code and saw that when I selected a Upload Quality option the summary was not updated. Studying your code I realized that in order to correct this, I simply added in the MainPreferenceFragment’s onCreate method this line of code:


    and again, thanks for this amazing tutorial.

  • Safiyulla Mona Kadmat

    please help me.. sir, i need one things, how to create keep screen on/off using toggle switch? how to setting up this setting for my app.? I Hope U

    • What will happen when this option is enabled?

      • Safiyulla Mona Kadmat

        Actualy i need source code

        • Find the code to lock screen that will turn off the screen.

  • Hi Ashok, here are the answers to your queries

    1Q) I think keeping return; statement after super.onBackPressed() will resolve the issue as the code is keep executing after that statement.

    2Q) To show a count in toolbar try the below code.

    3Q) You can check whether is navigation drawer opened on backpress and close it. Keep the below code at the begging of onBackPress method.
    Check the full code here in 16th step:

    public void onBackPressed() {
    if (drawer.isDrawerOpen(GravityCompat.START)) {

    4Q) Just create a Preference activity separately. When the settings options from Navigation Drawer is selected, using index / id you can identify the item selected. If it matches with the index of settings option, start the preference activity. Something similar to below.

    public boolean onNavigationItemSelected(MenuItem menuItem) {

    //Check to see which item was being clicked and perform appropriate action
    switch (menuItem.getItemId()) {

    case R.id.nav_settings:
    // launch new intent instead of loading fragment
    startActivity(new Intent(MainActivity.this, SettingsActivity.class));
    return true;
    navItemIndex = 0;

  • Vanessa Palacios

    Hi Ravi, how do I change the ellipsis that redirects to the Settings Screen to a gear icon?



    • You need to modify the menu xml file by adding your icon.

  • SABIT121

    Hi ravi my question is on different topic. the question is how can i show tap target view only for first time when the activity is opend ??

  • Np van der Spek

    Hallo Ravi, Thanks for the above explanations this was what i was searching for only i need on more step to understand and i did not found it anywhere so far.

    Could you explain how how to get and set the values programmaticaly. What i try to do is filling a database with the values set in the settings Activity. Is that possible and when so, can you give me some directions?

  • Shadman wakil

    I did exactly according to your tutorial, but the back button on actionBar in somehow not working.
    Any idea where I may be going wrong.


    • Did you overridden the onOptionsMenuSelected method?

      • Shadman wakil

        BIG THANKS @ravi8x:disqus.
        I missing it,

  • Niyo Blitari

    sir, how i can add toolbar to preferences settings if i use noactionbar theme for app root? thx before

  • Vhizama

    hi ravi, i want to add font preference for this lesson, please give me tutorial or references. thank a lot

  • Wilson Pagkalinawan

    Hi Ravi, thanks for the tutorial. I am doing right now, do you have a example on how to add a seekbarpreference?

    • Have you tried writing any code?

      • Wilson Pagkalinawan

        I’ve tried making a separate layout and using it like this

        Hence, the problem is that its attributes differ from SwitchPref or any other Pref objects.

  • SPM

    Hi Ravi,

    Why my checkbox color of checkbox preference is not changing ?
    It’s always white when enabled.
    Can you tell me what might be the reason ?

  • Hussain Haideri

    How to set an icon on the right side of Edit Preference

  • Chea Panha

    Sir ! i want to create notification using seekbar on message notification firebase in android studio.How can i do it?

  • Mohamed Sulaiman

    Thanks a lot for this tutorial. SeekBarPreference is missing. Can you pls add that too ?

  • areeba shakir

    i want to make these vibrate and sounds switches perform their respective tasks, but these are just dummy switches . can you please help how to on/off vibration or sound using these switches , i am making a location based reminder application. i am new in android so dont know much about it please help

  • adnane

    android.support.v7.widget.Toolbar toolbar = findViewById(R.id.toolbar);

    cant find R.id.toolbar help please

  • Shruti Kulkarni

    want to set background theme what can i do for it

  • Serge Kishiko

    Hey Ravi, Je suis ravi de découvrir cette article 😉
    Just to add something that took me a while before resolving it, is the “arrays.xml” must be in “res ⇒ values” folder. Adversely stated in the third step in Creating New Project :
    “Create new xml named arrays.xml under res ⇒ arrays.xml”

  • Great, but for send email prefere use ShareCompat.IntentFilter…

  • Tanvi Gupta

    Hi Ravi,
    Is there a way we can add a read only property in device settings for own app (Device Settings -> APP -> OWN APP INFO/DETAILS PAGE)

  • Sundar

    Out of curiosity Im asking,why do we need to write so much of boiler plate code just to create a menu. Shouldn’t developers be more focusing on writing the business logic?

    • Matteo Vettosi

      I think exactly the same. I’m just starting with android development and I find absurd that in 2019 we are required to write this quantity of boilerplate to achieve simple tasks that almost every app needs to do

  • Apurba Dutta

    Done by myself

  • tal vaknin


    Thanks for this guide.
    I have done all as described in your guide but I get this error:
    “Unable to find explicit activity class”

    • tal vaknin

      Update: I resolved this by adding the settings into the manifest. But, I guess it shouldn’t be like this.

      • LOVETH

        yes thats the right thing to do,i guess he just posted the most important ones and believes we should figure out the rest

  • Hi, im confusing about SettingsActivity.java with public class SettingsPrefActivity extends AppCompatPreferenceActivity beacuse it always give me error, when i try to change it to SettingsPrefActivity.java, it’s no error but app crash

  • Bob


    thanks very much for this tutorial !
    I am struggling to recreate the SettingsActivity after I have changed the language. I have taken care of setting the new locale, that works fine; in my MainActivity I have set up a listener for the sharedPreference and simply call recreate() which works well, but I cannot figure out how to recreate SettingsActivity (or MainPreferenceFragment) from within the OnPreferenceChangeListener…
    Thanks for your help !

  • Ron

    Very nice example for preferences!
    I think that the nested-static MainPreferenceFragment class, and the static functions, can actually be implemented as non-static. The PreferenceFragment functionality will not typically be reused by another SettingsActivity, so no memory leaks.

    This makes it much easier, in the listener methods, for example, to get a reference to the SettingsActivity, for accessing Intents, and other Activity-related resources.

  • hema

    how to change the checkbodPreference background color programmatically?

  • hema

    how to change the checkboxPreference background color programmatically?

  • A developer

    Very nice example. Thanks for this tutorial.
    I try to migrate to AndroidX but i can’t.
    Can you update the tutorial because some code is deprecated and i can’t fix the entire code.
    Thank you.

    • Prince Promise

      What’s the actual difficult you are facing?
      I can help you that.

  • Danilo Perfetti

    Hi Ravi, i am using a Preferences Settings Screen as one of the screens in a bottom navigation view and I would like to prevent it from displaying the home back arrow. Could you please show me how to do it? Thank you

  • Sukron Jazuli

    hello,can i use share function? thank.. help me