我正在尝试设置搜索栏/滑块的样式,例如Material Design Guidelines中标记为Discrete Slider - Click(具有小刻度线指示器)的那个。我无法弄清楚让刻度线出现的神奇咒语,有人知道怎么做吗?
我有 5 个位置 (0-4) 的搜索栏
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="4" />
我正在尝试设置搜索栏/滑块的样式,例如Material Design Guidelines中标记为Discrete Slider - Click(具有小刻度线指示器)的那个。我无法弄清楚让刻度线出现的神奇咒语,有人知道怎么做吗?
我有 5 个位置 (0-4) 的搜索栏
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="4" />
添加带有样式属性的刻度线:
<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>
现在您可以使用Slider
材料组件库中的 。
默认情况下,刻度线显示在离散滑块中。
<com.google.android.material.slider.Slider
android:valueFrom="0"
android:valueTo="10"
android:stepSize="1"
.../>