How to show tick marks for Discrete Slider?

后端 未结 2 829
不知归路
不知归路 2021-02-05 23:14

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 Gu

相关标签:
2条回答
  • 2021-02-05 23:26

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

    0 讨论(0)
  • 2021-02-05 23:38

    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>
    
    0 讨论(0)
提交回复
热议问题