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

SwitchPreferenceCompat

public class SwitchPreferenceCompat
extends TwoStatePreference

java.lang.Object
   ↳ android.support.v7.preference.Preference
     ↳ android.support.v7.preference.TwoStatePreference
       ↳ android.support.v7.preference.SwitchPreferenceCompat


A Preference that provides a two-state toggleable option.

This preference will store a boolean into the SharedPreferences.

Summary

Inherited XML attributes

From class android.support.v7.preference.Preference

Inherited constants

From class android.support.v7.preference.Preference

Inherited fields

From class android.support.v7.preference.TwoStatePreference

Public constructors

SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Construct a new SwitchPreference with the given style options.

SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr)

Construct a new SwitchPreference with the given style options.

SwitchPreferenceCompat(Context context, AttributeSet attrs)

Construct a new SwitchPreference with the given style options.

SwitchPreferenceCompat(Context context)

Construct a new SwitchPreference with default style options.

Public methods

CharSequence getSwitchTextOff()
CharSequence getSwitchTextOn()
void onBindViewHolder(PreferenceViewHolder holder)

Binds the created View to the data for this Preference.

void setSwitchTextOff(int resId)

Set the text displayed on the switch widget in the off state.

void setSwitchTextOff(CharSequence offText)

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.

Inherited methods

From class android.support.v7.preference.TwoStatePreference
From class android.support.v7.preference.Preference
From class java.lang.Object
From interface java.lang.Comparable

Public constructors

SwitchPreferenceCompat

added in version 24.1.0
SwitchPreferenceCompat (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Construct a new SwitchPreference with the given style options.

Parameters
context Context: The Context that will style this preference

attrs AttributeSet: Style attributes that differ from the default

defStyleAttr int: 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 int: 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.

SwitchPreferenceCompat

added in version 24.1.0
SwitchPreferenceCompat (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Construct a new SwitchPreference with the given style options.

Parameters
context Context: The Context that will style this preference

attrs AttributeSet: Style attributes that differ from the default

defStyleAttr int: 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.

SwitchPreferenceCompat

added in version 24.1.0
SwitchPreferenceCompat (Context context, 
                AttributeSet attrs)

Construct a new SwitchPreference with the given style options.

Parameters
context Context: The Context that will style this preference

attrs AttributeSet: Style attributes that differ from the default

SwitchPreferenceCompat

added in version 24.1.0
SwitchPreferenceCompat (Context context)

Construct a new SwitchPreference with default style options.

Parameters
context Context: The Context that will style this preference

Public methods

getSwitchTextOff

added in version 24.1.0
CharSequence getSwitchTextOff ()

Returns
CharSequence The text that will be displayed on the switch widget in the off state

getSwitchTextOn

added in version 24.1.0
CharSequence getSwitchTextOn ()

Returns
CharSequence The text that will be displayed on the switch widget in the on state

onBindViewHolder

added in version 24.1.0
void onBindViewHolder (PreferenceViewHolder holder)

Binds the created View to the data for this 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.

Parameters
holder PreferenceViewHolder: 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.

setSwitchTextOff

added in version 24.1.0
void setSwitchTextOff (int resId)

Set the text displayed on the switch widget in the off state. This should be a very short string; one word if possible.

Parameters
resId int: The text as a string resource ID

setSwitchTextOff

added in version 24.1.0
void setSwitchTextOff (CharSequence offText)

Set the text displayed on the switch widget in the off state. This should be a very short string; one word if possible.

Parameters
offText CharSequence: Text to display in the off state

setSwitchTextOn

added in version 24.1.0
void setSwitchTextOn (CharSequence onText)

Set the text displayed on the switch widget in the on state. This should be a very short string; one word if possible.

Parameters
onText CharSequence: Text to display in the on state

setSwitchTextOn

added in version 24.1.0
void setSwitchTextOn (int resId)

Set the text displayed on the switch widget in the on state. This should be a very short string; one word if possible.

Parameters
resId int: The text as a string resource ID