Skip to content
李涛 edited this page Mar 2, 2023 · 16 revisions

banner

Getting Started

  1. Maven library dependency
dependencies {

    implementation 'io.github.litao0621:nifty-slider:(latest version)'

    // Added effect for Sliders (Optional Features)
    implementation 'io.github.litao0621:nifty-slider-effect:(latest version)'

}
  1. Add it to the layout file
    <com.litao.slider.NiftySlider
        android:id="@+id/nifty_slider"
        android:layout_width="match_parent"
        android:layout_height="148dp"
        android:padding="16dp"
        android:value="50"
        android:valueFrom="0"
        android:valueTo="100"
        app:trackColor="@color/m3_demo_track_color"
        app:trackColorInactive="@color/m3_demo_track_inactive_color"
        app:thumbColor="@color/m3_demo_thumb_color"
        app:thumbShadowColor="@color/white"
        app:haloColor="@color/m3_demo_halo_color"/>
  1. Registers a callback to be invoked when the slider changes
        binding.niftySlider.setOnValueChangeListener { slider, value, fromUser ->
            //do something with float value
        }

        binding.niftySlider.setOnIntValueChangeListener { slider, value, fromUser ->
            //do something with int value
        }

        binding.niftySlider.setOnSliderTouchListener(object :NiftySlider.OnSliderTouchListener{
            override fun onStartTrackingTouch(slider: NiftySlider) {
                //do something on touch start
            }

            override fun onStopTrackingTouch(slider: NiftySlider) {
                //do something on touch stop
            }

        })

Custom Effects

  1. M3 Style

  1. WeRead Style

  1. Color Pick Style

Clone this wiki locally