Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between slider and seekbar in android

I am new to Android and i am learning SeekBars. in Google material design site i found Sliders from (com.google.android.material.slider.Slider) package instead of seekbars. I wonder what the difference is between Slider and SeekBar, which should I use and which is better? What is the purpose of implementing these two? I search a lot and There is no useful content on the internet

like image 847
Amir Ehsani Avatar asked Mar 02 '23 20:03

Amir Ehsani


1 Answers

The following may not be entirely accurate to the last detail, but it illustrates some of the history well enough:

Slider is just the MDC version of SeekBar - named a little differently and with a lot more functionality.

First, there was only SeekBar - the original framework UI component bundled with Android. Then, AndroidX libraries, previously called Support Libraries, were created for backporting new UI components and bugfixes to older phones which OEMs refused to update anymore. The AndroidX AppCompat subproject swaps out all your framework components for the "fixed" versions whenever you use AppCompatActivity. SeekBar -> AppCompatSeekBar, TextView -> AppCompatTextView... SeekBar and AppCompatSeekBar illustration

The old Support Libraries also had a package named design which contained some of the then-new Material 1.0 components (CardView and whatnot) which didn't have a framework counterpart. That's the reason why there is no AppCompatCardView - because there is no framework CardView, so there is nothing to "fix" with AppCompat.

If I recall correctly, the design package of the Support Libraries later became the starting point for the Android implementation of Material Components when Material 2.0 was unveiled. Material Design has its own version of SeekBar which is called Slider and it can do everything the old Android SeekBar can plus a lot more. Material Slider XML illustration

As for which one to use? (Neither is "better", that kind of thinking is inapplicable)

  • If you're using the MDC library already, or if you need some of Slider's advanced capabilities, use Slider.
  • If you only need a simple line with a circle sliding between two extremes, use SeekBar instead of pulling the MDC library just for that.
like image 82
Ondrej Karmazin Avatar answered Mar 08 '23 12:03

Ondrej Karmazin