SwitchPreferenceCompat
public class SwitchPreferenceCompat extends TwoStatePreference
| java.lang.Object | |||
| ↳ | androidx.preference.Preference | ||
| ↳ | androidx.preference.TwoStatePreference | ||
| ↳ | androidx.preference.SwitchPreferenceCompat |
A Preference that provides a two-state toggleable option.
This preference will save a boolean value to android.content.SharedPreferences.
name android:summaryOff
name android:summaryOn
name android:switchTextOff
name android:switchTextOn
name android:disableDependentsState
Summary
Public constructors |
|---|
SwitchPreferenceCompat(@NonNull Context context)Construct a new SwitchPreference with default style options. |
SwitchPreferenceCompat(Construct a new SwitchPreference with the given style options. |
SwitchPreferenceCompat(Construct a new SwitchPreference with the given style options. |
SwitchPreferenceCompat(Construct a new SwitchPreference with the given style options. |
Public methods |
|
|---|---|
@Nullable CharSequence |
|
@Nullable CharSequence |
|
void |
onBindViewHolder(@NonNull PreferenceViewHolder holder)Binds the created View to the data for this preference. |
void |
setSwitchTextOff(@Nullable 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(@Nullable 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 Constants |
||
|---|---|---|
|
Inherited fields |
||
|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
SwitchPreferenceCompat
public SwitchPreferenceCompat(@NonNull Context context)
Construct a new SwitchPreference with default style options.
SwitchPreferenceCompat
public SwitchPreferenceCompat(
@NonNull Context context,
@Nullable AttributeSet attrs
)
Construct a new SwitchPreference with the given style options.
| Parameters | |
|---|---|
@NonNull Context context |
The |
@Nullable AttributeSet attrs |
Style attributes that differ from the default |
SwitchPreferenceCompat
public SwitchPreferenceCompat(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
Construct a new SwitchPreference with the given style options.
| Parameters | |
|---|---|
@NonNull Context context |
The |
@Nullable AttributeSet attrs |
Style attributes that differ from the default |
int defStyleAttr |
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
public SwitchPreferenceCompat(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr,
int defStyleRes
)
Construct a new SwitchPreference with the given style options.
| Parameters | |
|---|---|
@NonNull Context context |
The |
@Nullable AttributeSet attrs |
Style attributes that differ from the default |
int defStyleAttr |
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. |
int 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 methods
getSwitchTextOff
public @Nullable CharSequence getSwitchTextOff()
| Returns | |
|---|---|
@Nullable CharSequence |
The text that will be displayed on the switch widget in the off state |
getSwitchTextOn
public @Nullable CharSequence getSwitchTextOn()
| Returns | |
|---|---|
@Nullable CharSequence |
The text that will be displayed on the switch widget in the on state |
onBindViewHolder
public void onBindViewHolder(@NonNull 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 | |
|---|---|
@NonNull PreferenceViewHolder 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. |
setSwitchTextOff
public void setSwitchTextOff(@Nullable 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 | |
|---|---|
@Nullable CharSequence offText |
Text to display in the off state |
setSwitchTextOff
public 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 | |
|---|---|
int resId |
The text as a string resource ID |
setSwitchTextOn
public void setSwitchTextOn(@Nullable 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 | |
|---|---|
@Nullable CharSequence onText |
Text to display in the on state |
setSwitchTextOn
public 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 | |
|---|---|
int resId |
The text as a string resource ID |