Skip to content
A slider (SeekBar) with amazing value label.
Branch: master
Clone or download
Latest commit 6efbff8 Apr 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea/codeStyles Update version to 1.0.2, Code tune Apr 15, 2019
app
discreteslider Fix typo Apr 17, 2019
gradle/wrapper Init Code 🚀 Apr 10, 2019
screenshots
.gitignore Init Code 🚀 Apr 10, 2019
LICENSE
README.md Update version to 1.0.4, Improve value label in other thumb radius Apr 17, 2019
build.gradle Init Code 🚀 Apr 10, 2019
gradle.properties Init Code 🚀 Apr 10, 2019
gradlew Init Code 🚀 Apr 10, 2019
gradlew.bat Init Code 🚀 Apr 10, 2019
settings.gradle Init Code 🚀 Apr 10, 2019

README.md

DiscreteSlider

JitPack license

DiscreteSlider tries to offer you the slider with value label as shown in the Material Design spec, with an API. The library also offer you range slider mode.

Screenshot

Normal Mode

Range Mode

Vertical Orientation

Setup

The easiest way to add the DiscreteSlider library to your project is by adding it as a dependency to your build.gradle

Step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.hearsilent:DiscreteSlider:1.0.4'
}

Usage

Setup Track in Java

mSlider.setTrackWidth(Utils.convertDpToPixel(4, this));
mSlider.setTrackColor(0xFFD81B60);
mSlider.setInactiveTrackColor(0x3DD81B60);

Setup Track in Xml

app:trackWidth="4dp"
app:trackColor="#D81B60"
app:inactiveTrackColor="#3DD81B60"

Setup Thumb in Java

mSlider.setThumbRadius(Utils.convertDpToPixel(6, this));
mSlider.setThumbColor(0xFFD81B60);
mSlider.setThumbPressedColor(0x1FD81B60);

Setup Thumb in Xml

app:thumbRadius="6dp"
app:thumbColor="#D81B60"
app:thumbPressedColor="#1FD81B60"

Setup TickMark in Java

mSlider.setTickMarkColor(0x3DFFFFFF);
mSlider.setTickMarkInactiveColor(0x1FD81B60);
mSlider.setTickMarkPatterns(Arrays.asList(new Dot(), new Dash(Utils.convertDpToPixel(1, this))));

Setup TickMark in Xml

app:tickMarkColor="#3DFFFFFF"
app:tickMarkInactiveColor="#1FD81B60"
<!-- Separated by commas, only accept `dot` or `dash`. You can also fill in "dot,dash,dash"-->
app:tickMarkPatterns="dot,dash"
app:tickMarkDashLength="1dp"

Setup ValueLabel in Java

mSlider.setValueLabelTextColor(Color.WHITE);
mSlider.setValueLabelTextSize(Utils.convertSpToPixel(16, this));
mSlider.setValueLabelGravity(DiscreteSlider.TOP);
// Customize value label's text by `setValueLabelFormatter`
mSlider.setValueLabelFormatter(new DiscreteSlider.ValueLabelFormatter() {

    @Override
    public String getLabel(int input) {
        return Integer.toString(input);
    }
});

Setup ValueLabel in Xml

app:valueLabelTextColor="#FFF"
app:valueLabelTextSize="16sp"
app:valueLabelGravity="top"

Setup Progress in Java

mSlider.setCount(21);
mSlider.setProgress(5); // The same as `setMinProgress`.
mSlider.setMinProgress(5);
mSlider.setMaxProgress(10); // Only can call in range mode.

Setup Progress in Xml

app:count="21"
app:minProgress="5"
app:maxProgress="5"

Get Progress in Java

mSlider.getProgress(); // The same as `getMinProgress`.
mSlider.getMinProgress();
mSlider.getMaxProgress();
mSlider.setOnValueChangedListener(new DiscreteSlider.OnValueChangedListener() {
    @Override
    // Only called when mode is {@Code MODE_NORMAL}
    public void onValueChanged(int progress) {
        super.onValueChanged(progress);
        Log.i("DiscreteSlider", "Progress: " + progress);
    }

    @Override
    // Only called when mode is {@Code MODE_RANGE}
    public void onValueChanged(int minProgress, int maxProgress) {
        super.onValueChanged(minProgress, maxProgress);
        Log.i("DiscreteSlider", "MinProgress: " + minProgress + ", MaxProgress: " + maxProgress);
    }
});

Setup Mode in Java

mSlider.setMode(DiscreteSlider.MODE_RANGE);

Setup Mode in Xml

app:mode="range"

Setup Click to Move in Java (By default is false)

mSlider.setClickable(true);

Setup Click to Move in Xml (By default is false)

android:clickable="true"
android:focusable="true"

Setup Orientation in Xml (By default is horizontal)

app:orientation="vertical"

Notice

Must set clipChildren to false in parent layout.

Compatibility

Android ICE CREAM SANDWICH 4.0+

Credits

This project was inspired by the Material Design spec by Google.

License

MIT License

Copyright (c) 2019 HearSilent

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You can’t perform that action at this time.