SwitchPreferenceCompat
class SwitchPreferenceCompat : TwoStatePreference
| kotlin.Any | |||
| ↳ | 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(context: Context)Construct a new SwitchPreference with default style options. |
SwitchPreferenceCompat(context: Context, attrs: AttributeSet?)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 functions |
|
|---|---|
CharSequence? |
|
CharSequence? |
|
Unit |
onBindViewHolder(holder: PreferenceViewHolder)Binds the created View to the data for this preference. |
Unit |
setSwitchTextOff(offText: CharSequence?)Set the text displayed on the switch widget in the off state. |
Unit |
setSwitchTextOff(resId: Int)Set the text displayed on the switch widget in the off state. |
Unit |
setSwitchTextOn(onText: CharSequence?)Set the text displayed on the switch widget in the on state. |
Unit |
setSwitchTextOn(resId: Int)Set the text displayed on the switch widget in the on state. |
Inherited Constants |
||
|---|---|---|
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
SwitchPreferenceCompat
SwitchPreferenceCompat(context: Context)
Construct a new SwitchPreference with default style options.
SwitchPreferenceCompat
SwitchPreferenceCompat(context: Context, attrs: AttributeSet?)
Construct a new SwitchPreference with the given style options.
| Parameters | |
|---|---|
context: Context |
The |
attrs: AttributeSet? |
Style attributes that differ from the default |
SwitchPreferenceCompat
SwitchPreferenceCompat(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int
)
Construct a new SwitchPreference with the given style options.
| Parameters | |
|---|---|
context: Context |
The |
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
SwitchPreferenceCompat(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int,
defStyleRes: Int
)
Construct a new SwitchPreference with the given style options.
| Parameters | |
|---|---|
context: Context |
The |
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. |
Public functions
getSwitchTextOff
fun getSwitchTextOff(): CharSequence?
| Returns | |
|---|---|
CharSequence? |
The text that will be displayed on the switch widget in the off state |
getSwitchTextOn
fun getSwitchTextOn(): CharSequence?
| Returns | |
|---|---|
CharSequence? |
The text that will be displayed on the switch widget in the on state |
onBindViewHolder
fun onBindViewHolder(holder: PreferenceViewHolder): Unit
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
fun setSwitchTextOff(offText: CharSequence?): Unit
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 |
setSwitchTextOff
fun setSwitchTextOff(resId: Int): Unit
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 |
setSwitchTextOn
fun setSwitchTextOn(onText: CharSequence?): Unit
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
fun setSwitchTextOn(resId: Int): Unit
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 |