How to show tick marks for Discrete Slider?

时间:2016-02-12 19:25:26

标签: android material-design seekbar

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" />

2 个答案:

答案 0 :(得分:16)

使用样式属性添加刻度线:

object Test {
  println("This does not print!")
  def add(a: Int, b: Int): Int = {print("Sum:" + a + b); a + b}
  add(2, 2)
}

// defined the above Test object

Test // executes the Test object

或者通过设置tickMark drawable手动添加它们:

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

tickmark.xml

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

答案 1 :(得分:0)

现在,您可以在材料组件库中使用Slider
刻度线默认显示在离散滑块中。

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

enter image description here