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
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() |
protected void |
onBindView(View view)
Binds the created View to the data for this Preference.
|
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
callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getEditor, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPersistedStringSet, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getTitleRes, getView, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToActivity, onAttachedToHierarchy, onCreateView, onDependencyChanged, onKey, onParentChanged, onPrepareForRemoval, peekExtras, performClick, persistBoolean, persistFloat, persistInt, persistLong, persistString, persistStringSet, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIntent, setKey, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, 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 preferenceprotected void onBindView(View view)
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.
onBindView
in class Preference
view
- The View that shows this Preference.Preference.onCreateView(ViewGroup)
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(@StringRes int resId)
resId
- The text as a string resource IDpublic void setSwitchTextOff(@StringRes int resId)
resId
- The text as a string resource IDpublic CharSequence getSwitchTextOn()
public CharSequence getSwitchTextOff()