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 defStyle)
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, onPrepareForRemoval, peekExtras, 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 defStyle)
context
- The Context that will style this preferenceattrs
- Style attributes that differ from the defaultdefStyle
- Theme attribute defining the default style optionspublic 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(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()