Google 致力于为黑人社区推动种族平等。查看具体举措

PreferenceManager

open class PreferenceManager
kotlin.Any
   ↳ androidx.preference.PreferenceManager

Used to help create Preference hierarchies from activities or XML.

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

Summary

Nested classes
abstract

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

abstract

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

abstract

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

abstract

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

open

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

Constants
static String

Public methods
open PreferenceScreen!

open T?

Finds a Preference with the given key.

open Context!

Returns the context.

open static SharedPreferences!

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

open PreferenceManager.OnDisplayPreferenceDialogListener!

open PreferenceManager.OnNavigateToScreenListener!

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

open PreferenceManager.OnPreferenceTreeClickListener!

open PreferenceManager.PreferenceComparisonCallback!

open PreferenceDataStore?

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

open PreferenceScreen!

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

open SharedPreferences!

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

open Int

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

open String!

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

open Boolean

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

open Boolean

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

open static Unit
setDefaultValues(context: Context!, resId: Int, readAgain: Boolean)

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

open static Unit
setDefaultValues(context: Context!, sharedPreferencesName: String!, sharedPreferencesMode: Int, resId: Int, readAgain: Boolean)

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

open Unit

open Unit

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

open Unit

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

open Unit

open Unit

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

open Boolean
setPreferences(preferenceScreen: PreferenceScreen!)

Sets the root of the preference hierarchy.

open Unit
setSharedPreferencesMode(sharedPreferencesMode: Int)

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

open Unit
setSharedPreferencesName(sharedPreferencesName: String!)

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

open Unit

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

open Unit

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

open Unit
showDialog(preference: Preference!)

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

Constants

KEY_HAS_SET_DEFAULT_VALUES

static val KEY_HAS_SET_DEFAULT_VALUES: String
Value: "_has_set_default_values"

Public methods

createPreferenceScreen

open fun createPreferenceScreen(context: Context!): PreferenceScreen!

findPreference

@Nullable open fun <T : Preference!> findPreference(@NonNull key: CharSequence): T?

Finds a Preference with the given key. Returns null if no Preference could be found with the given key.

Parameters
key CharSequence: The key of the Preference to retrieve
Return
T? The Preference with the key, or null

getContext

open fun getContext(): Context!

Returns the context.

Return
Context! The Context

getDefaultSharedPreferences

open static fun getDefaultSharedPreferences(context: Context!): SharedPreferences!

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
Return
SharedPreferences! A SharedPreferences instance that can be used to retrieve and listen to values of the preferences

getOnDisplayPreferenceDialogListener

open fun getOnDisplayPreferenceDialogListener(): PreferenceManager.OnDisplayPreferenceDialogListener!

getOnNavigateToScreenListener

open fun getOnNavigateToScreenListener(): PreferenceManager.OnNavigateToScreenListener!

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

getOnPreferenceTreeClickListener

open fun getOnPreferenceTreeClickListener(): PreferenceManager.OnPreferenceTreeClickListener!

getPreferenceComparisonCallback

open fun getPreferenceComparisonCallback(): PreferenceManager.PreferenceComparisonCallback!

getPreferenceDataStore

@Nullable