12

在此处输入图像描述

我正在尝试设置搜索栏/滑块的样式,例如Material Design Guidelines中标记为Discrete Slider - Click(具有小刻度线指示器)的那个。我无法弄清楚让刻度线出现的神奇咒语,有人知道怎么做吗?

我有 5 个位置 (0-4) 的搜索栏

<SeekBar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="4" />
4

2 回答 2

20

添加带有样式属性的刻度线:

<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 drawable 手动添加它们:

<SeekBar
    android:id="@+id/seekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="10"
    android:tickMark="@drawable/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>
于 2016-09-14T10:13:33.683 回答
1

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

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

在此处输入图像描述

于 2020-08-01T07:31:26.490 回答