[英]How to add tickmark with selected value for Discrete Sliders?
我正在嘗試對離散搜索欄進行樣式設置,例如在Material design網站上顯示的“聚焦搜索欄”,但我不知道如何在顯示所選值的欄上添加刻度線
我有一個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" />
感謝幫助
您必須將刻度標記drable添加到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:tickMark="@drawable/your_tickmark_drawable" // this line you have to add
android:max="100"
android:progress="1" />
我有解決方案創建一個名為“ thumb.xml”的新可繪制對象,其中包含對png文件的引用和一個參數android:bottom,該參數設置為適當的水平,以確保拇指在搜索欄上完美對齊(在我的情況下為50dp) :
<?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"/>
添加對勾標記可繪制對象對我不起作用,因為我需要更改和移動拇指。 希望這會有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.