added in version 24.1.0
belongs to Maven artifact com.android.support:preference-v7:28.0.0-alpha1

PreferenceManager

public class PreferenceManager
extends Object

java.lang.Object
   ↳ android.support.v7.preference.PreferenceManager


Used to help create Preference hierarchies from activities or XML.

In most cases, clients should use addPreferencesFromResource(int), or addPreferencesFromResource(int).

Summary

Nested classes

interface PreferenceManager.OnDisplayPreferenceDialogListener

Interface definition for a class that will be called when a Preference requests to display a dialog. 

interface PreferenceManager.OnNavigateToScreenListener

Interface definition for a class that will be called when a PreferenceScreen requests navigation. 

interface PreferenceManager.OnPreferenceTreeClickListener

Interface definition for a callback to be invoked when a Preference in the hierarchy rooted at this PreferenceScreen is clicked. 

class PreferenceManager.PreferenceComparisonCallback

Callback class to be used by the RecyclerView.Adapter associated with the PreferenceScreen, used to determine when two Preference objects are semantically and visually the same. 

class PreferenceManager.SimplePreferenceComparisonCallback

A basic implementation of PreferenceManager.PreferenceComparisonCallback suitable for use with the default Preference classes. 

Constants

String KEY_HAS_SET_DEFAULT_VALUES

Public methods

PreferenceScreen createPreferenceScreen(Context context)
Preference findPreference(CharSequence key)

Finds a Preference based on its key.

Context getContext()

Returns the context.

static SharedPreferences getDefaultSharedPreferences(Context context)

Gets a SharedPreferences instance that points to the default file that is used by the preference framework in the given context.

PreferenceManager.OnDisplayPreferenceDialogListener getOnDisplayPreferenceDialogListener()
PreferenceManager.OnNavigateToScreenListener getOnNavigateToScreenListener()

Returns the PreferenceManager.OnNavigateToScreenListener, if one has been set.

PreferenceManager.OnPreferenceTreeClickListener getOnPreferenceTreeClickListener()
PreferenceManager.PreferenceComparisonCallback getPreferenceComparisonCallback()
PreferenceDataStore getPreferenceDataStore()

Returns the PreferenceDataStore associated with this manager or null if the default SharedPreferences are used instead.

PreferenceScreen getPreferenceScreen()

Returns the root of the preference hierarchy managed by this class.

SharedPreferences getSharedPreferences()

Gets a SharedPreferences instance that preferences managed by this will use.

int getSharedPreferencesMode()

Returns the current mode of the SharedPreferences file that preferences managed by this will use.

String getSharedPreferencesName()

Returns the current name of the SharedPreferences file that preferences managed by this will use.

boolean isStorageDefault()

Indicates if the storage location used internally by this class is the default provided by the hosting Context.

boolean isStorageDeviceProtected()

Indicates if the storage location used internally by this class is backed by device-protected storage.

static void setDefaultValues(Context context, String sharedPreferencesName, int sharedPreferencesMode, int resId, boolean readAgain)

Similar to setDefaultValues(Context, int, boolean) but allows the client to provide the filename and mode of the shared preferences file.

static void setDefaultValues(Context context, int resId, boolean readAgain)

Sets the default values from an XML preference file by reading the values defined by each Preference item's android:defaultValue attribute.

void setOnDisplayPreferenceDialogListener(PreferenceManager.OnDisplayPreferenceDialogListener onDisplayPreferenceDialogListener)
void setOnNavigateToScreenListener(PreferenceManager.OnNavigateToScreenListener listener)

Sets the callback to be invoked when a PreferenceScreen in the hierarchy rooted at this PreferenceManager is clicked.

void setOnPreferenceTreeClickListener(PreferenceManager.OnPreferenceTreeClickListener listener)

Sets the callback to be invoked when a Preference in the hierarchy rooted at this PreferenceManager is clicked.

void setPreferenceComparisonCallback(PreferenceManager.PreferenceComparisonCallback preferenceComparisonCallback)
void setPreferenceDataStore(PreferenceDataStore dataStore)

Sets a PreferenceDataStore to be used by all Preferences associated with this manager that don't have a custom PreferenceDataStore assigned via setPreferenceDataStore(PreferenceDataStore).

boolean setPreferences(PreferenceScreen preferenceScreen)

Sets the root of the preference hierarchy.

void setSharedPreferencesMode(int sharedPreferencesMode)

Sets the mode of the SharedPreferences file that preferences managed by this will use.

void setSharedPreferencesName(String sharedPreferencesName)

Sets the name of the SharedPreferences file that preferences managed by this will use.

void setStorageDefault()

Sets the storage location used internally by this class to be the default provided by the hosting Context.

void setStorageDeviceProtected()

Explicitly set the storage location used internally by this class to be device-protected storage.

void showDialog(Preference preference)

Called when a preference requests that a dialog be shown to complete a user interaction.

Inherited methods

From class java.lang.Object

Constants

KEY_HAS_SET_DEFAULT_VALUES

added in version 24.1.0
String KEY_HAS_SET_DEFAULT_VALUES

Constant Value: "_has_set_default_values"

Public methods

createPreferenceScreen

added in version 24.1.0
PreferenceScreen createPreferenceScreen (Context context)

Parameters
context Context

Returns
PreferenceScreen

findPreference

added in version 24.1.0
Preference findPreference (CharSequence key)

Finds a Preference based on its key.

Parameters
key CharSequence: The key of the preference to retrieve.

Returns
Preference The Preference with the key, or null.

getContext

added in version 24.1.0
Context getContext ()

Returns the context.

Returns
Context The context.

getDefaultSharedPreferences

added in version 24.1.0
SharedPreferences getDefaultSharedPreferences (Context context)

Gets a SharedPreferences instance that points to the default file that is used by the preference framework in the given context.

Parameters
context Context: The context of the preferences whose values are wanted.

Returns
SharedPreferences A SharedPreferences instance that can be used to retrieve and listen to values of the preferences.

getOnDisplayPreferenceDialogListener

added in version 24.1.0
PreferenceManager.OnDisplayPreferenceDialogListener getOnDisplayPreferenceDialogListener ()

Returns
PreferenceManager.OnDisplayPreferenceDialogListener

getOnNavigateToScreenListener

added in version 24.1.0
PreferenceManager.OnNavigateToScreenListener getOnNavigateToScreenListener ()

Returns the PreferenceManager.OnNavigateToScreenListener, if one has been set.

Returns
PreferenceManager.OnNavigateToScreenListener

getOnPreferenceTreeClickListener

added in version 24.1.0
PreferenceManager.OnPreferenceTreeClickListener getOnPreferenceTreeClickListener ()

Returns
PreferenceManager.OnPreferenceTreeClickListener