SeekBarPreference
public class SeekBarPreference extends Preference
Preference based on android.preference.SeekBarPreference but uses support preference as a base . It contains a title and a SeekBar and an optional SeekBar value TextView. The actual preference layout is customizable by setting android:layout on the preference widget layout or seekBarPreferenceStyle attribute.
The SeekBar within the preference can be defined adjustable or not by setting
adjustable attribute. If adjustable, the preference will be responsive to DPAD left/right keys. Otherwise, it skips those keys.
The SeekBar value view can be shown or disabled by setting showSeekBarValue attribute to true or false, respectively.
Other SeekBar specific attributes (e.g. title, summary, defaultValue, min,
max) can be set directly on the preference widget layout.
Summary
Public constructors |
|---|
SeekBarPreference(@NonNull Context context) |
SeekBarPreference(@NonNull Context context, @Nullable AttributeSet attrs) |
SeekBarPreference( |
SeekBarPreference( |
Public methods |
|
|---|---|
int |
getMax()Gets the upper bound set on the |
int |
getMin()Gets the lower bound set on the |
final int |
Returns the amount of increment change via each arrow key click. |
boolean |
Gets whether the current |
boolean |
Gets whether the |
int |
getValue()Gets the current progress of the |
boolean |
Gets whether the |
void |
onBindViewHolder(@NonNull PreferenceViewHolder holder)Binds the created View to the data for this preference. |
void |
setAdjustable(boolean adjustable)Sets whether the |
final void |
setMax(int max)Sets the upper bound on the |
void |
setMin(int min)Sets the lower bound on the |
final void |
setSeekBarIncrement(int seekBarIncrement)Sets the increment amount on the |
void |
setShowSeekBarValue(boolean showSeekBarValue)Sets whether the current |
void |
setUpdatesContinuously(boolean updatesContinuously)Sets whether the |
void |
setValue(int seekBarValue)Sets the current progress of the |
Protected methods |
|
|---|---|
@Nullable Object |
onGetDefaultValue(@NonNull TypedArray a, int index)Called when a preference is being inflated and the default value attribute needs to be read. |
void |
onRestoreInstanceState(@Nullable Parcelable state)Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by |
@Nullable Parcelable |
Hook allowing a preference to generate a representation of its internal state that can later be used to create a new instance with that same state. |
void |
onSetInitialValue(Object defaultValue)Implement this to set the initial value of the preference. |
Inherited Constants |
||
|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
SeekBarPreference
public SeekBarPreference(@NonNull Context context, @Nullable AttributeSet attrs)
SeekBarPreference
public SeekBarPreference(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
SeekBarPreference
public SeekBarPreference(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr,
int defStyleRes
)
Public methods
getMax
public int getMax()
Gets the upper bound set on the SeekBar.
| Returns | |
|---|---|
int |
The upper bound set |
getMin
public int getMin()
Gets the lower bound set on the SeekBar.
| Returns | |
|---|---|
int |
The lower bound set |
getSeekBarIncrement
public final int getSeekBarIncrement()
Returns the amount of increment change via each arrow key click. This value is derived from user's specified increment value if it's not zero. Otherwise, the default value is picked from the default mKeyProgressIncrement value in android.widget.AbsSeekBar.
| Returns | |
|---|---|
int |
The amount of increment on the |
getShowSeekBarValue
public boolean getShowSeekBarValue()
Gets whether the current SeekBar value is displayed to the user.
| Returns | |
|---|---|
boolean |
Whether the current |
| See also | |
|---|---|
setShowSeekBarValue |
getUpdatesContinuously
public boolean getUpdatesContinuously()
Gets whether the SeekBarPreference should continuously save the SeekBar value while it is being dragged. Note that when the value is true, Preference.OnPreferenceChangeListener will be called continuously as well.
| Returns | |
|---|---|
boolean |
Whether the |
| See also | |
|---|---|
setUpdatesContinuously |
getValue
public int getValue()
Gets the current progress of the SeekBar.
| Returns | |
|---|---|
int |
The current progress of the |
isAdjustable
public boolean isAdjustable()
Gets whether the SeekBar should respond to the left/right keys.
| Returns | |
|---|---|
boolean |
Whether the |
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. |
setAdjustable
public void setAdjustable(boolean adjustable)
Sets whether the SeekBar should respond to the left/right keys.
| Parameters | |
|---|---|
boolean adjustable |
Whether the |
setMax
public final void setMax(int max)
Sets the upper bound on the SeekBar.
| Parameters | |
|---|---|
int max |
The upper bound to set |
setMin
public void setMin(int min)
Sets the lower bound on the SeekBar.
| Parameters | |
|---|---|
int min |
The lower bound to set |
setSeekBarIncrement
public final void setSeekBarIncrement(int seekBarIncrement)
Sets the increment amount on the SeekBar for each arrow key press.
| Parameters | |
|---|---|
int seekBarIncrement |
The amount to increment or decrement when the user presses an arrow key. |
setShowSeekBarValue
public void setShowSeekBarValue(boolean showSeekBarValue)
Sets whether the current SeekBar value is displayed to the user.
| Parameters | |
|---|---|
boolean showSeekBarValue |
Whether the current |
| See also | |
|---|---|
getShowSeekBarValue |
setUpdatesContinuously
public void setUpdatesContinuously(boolean updatesContinuously)
Sets whether the SeekBarPreference should continuously save the SeekBar value while it is being dragged.
| Parameters | |
|---|---|
boolean updatesContinuously |
Whether the |
| See also | |
|---|---|
getUpdatesContinuously |
Protected methods
onGetDefaultValue
protected @Nullable Object onGetDefaultValue(@NonNull TypedArray a, int index)
Called when a preference is being inflated and the default value attribute needs to be read. Since different preference types have different value types, the subclass should get and return the default value which will be its value type.
For example, if the value type is String, the body of the method would proxy to getString.
| Parameters | |
|---|---|
@NonNull TypedArray a |
The set of attributes |
int index |
The index of the default value attribute |
onRestoreInstanceState
protected void onRestoreInstanceState(@Nullable Parcelable state)
Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState. This function will never be called with a null state.
| Parameters | |
|---|---|
@Nullable Parcelable state |
The saved state that had previously been returned by |
| See also | |
|---|---|
onSaveInstanceState |
|
restoreHierarchyState |
onSaveInstanceState
protected @Nullable Parcelable onSaveInstanceState()
Hook allowing a preference to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can be reconstructed later.
| Returns | |
|---|---|
@Nullable Parcelable |
A Parcelable object containing the current dynamic state of this preference, or |
| See also | |
|---|---|
onRestoreInstanceState |
|
saveHierarchyState |
onSetInitialValue
protected void onSetInitialValue(Object defaultValue)
Implement this to set the initial value of the preference.
If you are persisting values to SharedPreferences or a PreferenceDataStore you should restore the saved value for the preference.
If you are not persisting values, or there is no value saved for the preference, you should set the value of the preference to defaultValue.
| Parameters | |
|---|---|
Object defaultValue |
The default value for the preference if set, otherwise |