【问题标题】:How to add tickmark with selected value for Discrete Sliders?如何为离散滑块添加带有选定值的刻度线?
【发布时间】:2017-09-13 08:05:54
【问题描述】:
我正在尝试设置离散搜索栏的样式,例如 Material design 网站中显示的 Focused Seekbar,但我无法弄清楚如何在显示所选值的栏上添加刻度线
Material Design discrete sliders
我有一个有 100 个位置的搜索栏,这是我当前的 xml 代码:
<SeekBar
android:id="@+id/seekBar"
style="@style/Widget.AppCompat.SeekBar.Discrete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/mod_quantity_text"
android:clickable="true"
android:max="100"
android:progress="1" />
感谢您的帮助
【问题讨论】:
标签:
android
material-design
android-seekbar
【解决方案1】:
你必须在你的 XML 中添加 tickmark drable
<SeekBar
android:id="@+id/seekBar"
style="@style/Widget.AppCompat.SeekBar.Discrete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/mod_quantity_text"
android:clickable="true"
android:tickMark="@drawable/your_tickmark_drawable" // this line you have to add
android:max="100"
android:progress="1" />
【解决方案2】:
我有解决方案创建一个名为“thumb.xml”的新drawable,其中包含对png文件的引用和一个设置为适当级别的参数android:bottom以保证拇指在seekbar上的完美对齐(50dp in我的情况):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="50dp"
android:drawable="@drawable/seekbar_thumb"/>
</layer-list>
在此之后,我更改了布局 xml 文件中的 SeekBar 参数,添加了自定义拇指(和相关颜色):
<SeekBar
android:id="@+id/seekBar"
style="@style/Widget.AppCompat.SeekBar"
android:layout_width="match_parent"
android:layout_height="95dp"
android:minHeight="20dp"
android:clickable="true"
android:progressBackgroundTint="@color/colorPrimary"
android:max="100"
android:thumb="@drawable/thumb"
android:thumbTint="@color/colorAccent"
android:progress="1"/>
添加标记可绘制对我不起作用,因为我需要更改和移动拇指。
希望这会有所帮助