I referenced this https://github.com/warkiz/TickSeekBar
I want to change 0 33 57 100
values in the photo to 2 4 6 8
And I want to show that value as a log
I've tried several values but couldn't make it work.
<com.warkiz.tickseekbar.TickSeekBar android:id="@+id/tsb1" android:layout_width="286dp" android:layout_height="wrap_content" app:tsb_ticks_count="4" app:tsb_thumb_color="@color/skyblue" app:tsb_thumb_size="16dp" app:tsb_show_tick_marks_type ="oval" app:tsb_tick_marks_color="@color/skyblue" app:tsb_tick_marks_size="8dp" app:tsb_show_tick_texts="below" app:tsb_tick_texts_color="@color/black" app:tsb_tick_texts_size="17sp" app:tsb_track_background_color="@color/divid_color" app:tsb_track_background_size="2dp" app:tsb_track_progress_color="@color/skyblue" app:tsb_track_progress_size="3dp" android:layout_marginTop="90dp" android:layout_marginLeft="40dp"/>
val seekBar = TickSeekBar .with(context!!) .max(7F) .min(1F) .progressValueFloat(true) .progress(33f) .tickCount(7) .showTickMarksType(TickMarkType.DIVIDER) .tickMarksColor(resources.getColor(R.color.skyblue)) .tickMarksSize(6) //dp .tickTextsSize(13) //sp .showTickTextsPosition(TextPosition.ABOVE) .tickTextsColorStateList(resources.getColorStateList(R.color.skyblue)) .thumbColor(Color.parseColor("#ff0000")) .thumbSize(14) .trackProgressColor(resources.getColor(R.color.colorAccent)) .trackProgressSize(4) .trackBackgroundColor(resources.getColor(R.color.skyblue)) .trackBackgroundSize(2) .build()
In the xml file, add these two lines:
<com.warkiz.tickseekbar.TickSeekBar
...
app:tsb_min="2"
app:tsb_max="8"/>
And to get the value as a Log
, do this in the Kotlin file:
var tickSeekBar: TickSeekBar = findViewById(R.id.tsb1)
tickSeekBar.onSeekChangeListener =
object : OnSeekChangeListener {
override fun onSeeking(seekParams: SeekParams?) {
}
override fun onStartTrackingTouch(seekBar: TickSeekBar?) {
}
override fun onStopTrackingTouch(seekBar: TickSeekBar?) {
if (seekBar != null) {
Toast.makeText(applicationContext, seekBar.progress.toString(), Toast.LENGTH_SHORT).show()
Log.d("abc", seekBar.progress.toString())
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.