public class SwitchPreference extends TwoStatePreference
Preference
that provides a two-state toggleable option.
This preference will store a boolean into the SharedPreferences.
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
mChecked
DEFAULT_ORDER
Constructor and Description |
---|
SwitchPreference(Context context)
Construct a new SwitchPreference with default style options.
|
SwitchPreference(Context context,
AttributeSet attrs)
Construct a new SwitchPreference with the given style options.
|
SwitchPreference(Context context,
AttributeSet attrs,
int defStyleAttr)
Construct a new SwitchPreference with the given style options.
|
SwitchPreference(Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Construct a new SwitchPreference with the given style options.
|
Modifier and Type | Method and Description |
---|---|
CharSequence |
getSwitchTextOff() |
CharSequence |
getSwitchTextOn() |
void |
onBindViewHolder(PreferenceViewHolder holder)
Binds the created View to the data for this Preference.
|
protected void |
performClick(View view) |
void |
setSwitchTextOff(CharSequence offText)
Set the text displayed on the switch widget in the off state.
|
void |
setSwitchTextOff(int resId)
Set the text displayed on the switch widget in the off state.
|
void |
setSwitchTextOn(CharSequence onText)
Set the text displayed on the switch widget in the on state.
|
void |
setSwitchTextOn(int resId)
Set the text displayed on the switch widget in the on state.
|
getDisableDependentsState, getSummaryOff, getSummaryOn, isChecked, onClick, onGetDefaultValue, onRestoreInstanceState, onSaveInstanceState, onSetInitialValue, setChecked, setDisableDependentsState, setSummaryOff, setSummaryOff, setSummaryOn, setSummaryOn, shouldDisableDependents, syncSummaryView, syncSummaryView
callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, isVisible, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttached, onAttachedToHierarchy, onAttachedToHierarchy, onDependencyChanged, onDetached, onInitializeAccessibilityNodeInfo, onParentChanged, onPrepareForRemoval, peekExtras, performClick, persistBoolean, persistFloat, persistInt, persistLong, persistString, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIntent, setKey, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setViewId, setVisible, setWidgetLayoutResource, shouldPersist, toString
public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
context
- The Context that will style this preferenceattrs
- Style attributes that differ from the defaultdefStyleAttr
- An attribute in the current theme that contains a
reference to a style resource that supplies default values for
the view. Can be 0 to not look for defaults.defStyleRes
- A resource identifier of a style resource that
supplies default values for the view, used only if
defStyleAttr is 0 or can not be found in the theme. Can be 0
to not look for defaults.public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr)
context
- The Context that will style this preferenceattrs
- Style attributes that differ from the defaultdefStyleAttr
- An attribute in the current theme that contains a
reference to a style resource that supplies default values for
the view. Can be 0 to not look for defaults.public SwitchPreference(Context context, AttributeSet attrs)
context
- The Context that will style this preferenceattrs
- Style attributes that differ from the defaultpublic SwitchPreference(Context context)
context
- The Context that will style this preferencepublic void onBindViewHolder(PreferenceViewHolder holder)
Preference
This is a good place to grab references to custom Views in the layout and set properties on them.
Make sure to call through to the superclass's implementation.
onBindViewHolder
in class Preference
holder
- The ViewHolder that provides references to the views to fill in. These views
will be recycled, so you should not hold a reference to them after this method
returns.public void setSwitchTextOn(CharSequence onText)
onText
- Text to display in the on statepublic void setSwitchTextOff(CharSequence offText)
offText
- Text to display in the off statepublic void setSwitchTextOn(int resId)
resId
- The text as a string resource IDpublic void setSwitchTextOff(int resId)
resId
- The text as a string resource IDpublic CharSequence getSwitchTextOn()
public CharSequence getSwitchTextOff()
protected void performClick(View view)
performClick
in class Preference