12

enter image description here

I'm trying to style a seekbar/slider like the one labeled Discrete Slider - Click (that has the little tick mark indicators) in the Material Design Guidelines. I can't figure out the magical incantation to have the tickmarks show up, does anyone know how to do this?

I have a seekbar with 5 positions (0-4)

<SeekBar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="4" />
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
jt-gilkeson
  • 2,661
  • 1
  • 30
  • 40

3 Answers3

22

Add tick marks with the style attribute:

<SeekBar
    android:id="@+id/seekBar"
    style="@style/Widget.AppCompat.SeekBar.Discrete"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="10"
    />

Or add them manually by setting the tickMark drawable:

<SeekBar
    android:id="@+id/seekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="10"
    android:tickMark="@drawable/tickmark"
    />

tickmark.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="oval">
    <size android:width="4dp"
          android:height="4dp"/>
    <solid android:color="@android:color/white"/>
</shape>
jt-gilkeson
  • 2,661
  • 1
  • 30
  • 40
NameSpace
  • 10,009
  • 3
  • 39
  • 40
3

Now you can use the Slider in the Material Components Library.
The tick marks are displayed by default in the discrete sliders.

    <com.google.android.material.slider.Slider
        android:valueFrom="0"
        android:valueTo="10"
        android:stepSize="1"
        .../>

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
0

use com.google.android.material.slider.Slider

app:tickVisible="true" // false
Trang Đỗ
  • 160
  • 1
  • 9