This library provides a SeekBar similar to the default Android one, but with two thumb controls allowing a range to be selected.
Main features:
- Two thumbs allowing a range to be selected
- Supports integer ranges and floating point ranges
- Text indicating the selected min and max values on the bar
- Smoother drag animation
- NEW: Step/Interval support - Snap values to discrete steps
- NEW: Min/Max range constraints - Enforce minimum/maximum gap between thumbs
- NEW: Custom value formatter - Format displayed values (e.g., currency, percentage)
- NEW: Extended listener callbacks - Get notified when tracking starts/stops
- NEW: Accessibility support - Full TalkBack and screen reader support
- NEW: RTL support - Right-to-left layout support for international users
- NEW: Animation support - Smooth animated transitions for programmatic value changes
Customizations:
- Ability to initialise from XML, with attributes (only tested for Integer and Double, would not support all the original types that the class supports when initialized programmatically)
- Ability to make the range-seek-bar only use one thumb instead of two, with all other feature remaining; can be set from XML. This makes it more similar to the default android seekbar, but you still benefit from the other features and very smooth animation.
- Text above thumbs can be disabled and colour can be changed
- Custom icons can be used for the thumbs
- NEW: Step value can be set from XML or code
- NEW: Min/Max range can be set from XML or code
Should be able to import, build and run in Android Studio or from the command line with gradle. The androidrangeseekbar-sample shows the available features and customizations in code and XML.
-
Add this in your build.gradle file:
-
For latest release:
Download
Repository available on jCenter
compile 'com.ianpinto.androidrangeseekbar:androidrangeseekbar:1.0.0'
If the dependency fails to resolve, add this to your project repositories
repositories { maven { url "https://dl.bintray.com/ian-pinto/maven" } }
Set discrete steps for the slider:
In XML:
<com.ianpinto.androidrangeseekbar.rangeseekbar.RangeSeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
rsb:absoluteMinValue="0"
rsb:absoluteMaxValue="100"
rsb:steps="5" />In Code:
RangeSeekBar<Integer> seekBar = new RangeSeekBar<>(context);
seekBar.setRangeValues(0, 100);
seekBar.setSteps(5); // Snap to multiples of 5Enforce minimum or maximum gap between thumbs:
In XML:
<com.ianpinto.androidrangeseekbar.rangeseekbar.RangeSeekBar
rsb:minRange="10"
rsb:maxRange="50" />In Code:
seekBar.setMinRange(10); // Minimum gap of 10
seekBar.setMaxRange(50); // Maximum gap of 50Format displayed values (e.g., currency, percentage):
seekBar.setValueFormatter(new RangeSeekBar.ValueFormatter() {
@Override
public String format(Number value) {
return "$" + NumberFormat.getInstance().format(value);
}
});Get notified when user starts/stops dragging:
seekBar.setOnRangeSeekBarChangeListener(new RangeSeekBar.OnRangeSeekBarChangeListenerExtended<Integer>() {
@Override
public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
// Called when values change
}
@Override
public void onStartTrackingTouch(RangeSeekBar<?> bar, RangeSeekBar.Thumb thumb) {
// Called when user starts dragging
}
@Override
public void onStopTrackingTouch(RangeSeekBar<?> bar, RangeSeekBar.Thumb thumb) {
// Called when user stops dragging
}
});Enable smooth animations when changing values programmatically:
seekBar.setAnimateChanges(true);
seekBar.setAnimationDuration(500); // milliseconds
// Values will now animate smoothly
seekBar.setSelectedMinValue(30);
seekBar.setSelectedMaxValue(70);
// Or animate specific changes
seekBar.setSelectedMinValue(50, true); // Animate this change
seekBar.setSelectedMaxValue(80, false); // Don't animate this changeThe android-range-seek-bar started as a fork of the following project: https://code.google.com/p/range-seek-bar/ under Apache license.
The images are licensed under Creative Commons ( http://creativecommons.org/licenses/by/3.0/ ). The originals are provided in the original project ( https://code.google.com/p/range-seek-bar/ ) and seek_thumb_disabled.png is added by us.
The source code is licensed under the Apache License. A copy of this can be found at http://www.apache.org/licenses/LICENSE-2.0 and has been included in the repository as well.
