In this tutorial, we’ll discuss and implement SeekBar in our Android Application using Kotlin.
在本教程中,我们将使用Kotlin在Android应用程序中讨论和实现SeekBar。
什么是Android SeekBar? (What is Android SeekBar?)
SeekBar is a UI element that is an extension of the ProgressBar.
SeekBar是一个UI元素,它是ProgressBar的扩展。
SeekBar adds a draggable thumb to the ProgressBar. It is commonly used in music apps to provide volume control.
SeekBar将可拖动的拇指添加到ProgressBar。 它通常在音乐应用中用于提供音量控制。
SeekBar is like a scale with an upper and lower limit and every step is a single unit.
SeekBar就像一个具有上限和下限的标尺,每个步骤都是一个单位。
SeekBar XML属性 (SeekBar XML Attributes)
Some of the important XML attributes of SeekBar are:
SeekBar的一些重要XML属性是:
android:minWidth/maxWidth/minHeight/maxHeight
: these attributes are used to set the dimensions of the seekbar view. They don’t change the thickness of the SeekBar.android:minWidth/maxWidth/minHeight/maxHeight
:这些属性用于设置搜索栏视图的尺寸。 它们不会更改SeekBar的厚度。android:max/min
: The upper/lower limit of the SeekBar. The android:min is available from Android SDK 26 and above.android:max/min
:SeekBar的上限/下限。 android:min可从Android SDK 26及更高版本中获得。android:progress
: The current value of the thumb position.android:progress
:拇指位置的当前值。android:progressTint
: Here we pass the color for the progress to the left of the thumb position.android:progressTint
:在这里,我们将android:progressTint
的颜色传递到拇指位置的左侧。android:progressBackgroundTint
: This color is displayed for the SeekBar background, to the right of the thumb.android:progressBackgroundTint
:此颜色显示在拇指右边的SeekBar背景中。android:thumb
: Here we can pass a custom drawable that will act as the thumb of the seek bar.android:thumb
:这里我们可以传递一个自定义的drawable,它将用作搜索栏的拇指。android:thumbTint
: color of the thumb.android:thumbTint
:拇指的颜色。android:thumbOffset
: The distance between the thumb and the current progress indp
. A negative value shifts the thumb to the right of the progress. A positive one shifts it to the left.android:thumbOffset
:拇指与dp
当前进度之间的距离。 负值会将拇指移到进度的右侧。 正数将其向左移动。style
: it’s used to set custom/predefined styles on the SeekBar. There is a popular seekbar style – “Discrete” – which breaks the progress into discrete intervals.style
:用于在SeekBar上设置自定义/预定义的样式。 有一种流行的搜索栏样式-“离散”-将进度分为离散间隔。android:tickMark
: Here we pass a drawable, which acts as breakpoints on the SeekBar. The number of breakpoints/tickMarks is equal to android:max.android:tickMark
:这里我们传递了一个drawable,它用作SeekBar上的断点。 断点/刻度标记的数量等于android:max。android:tickMarkTint
: used to set a color on the tickMark drawable.android:tickMarkTint
:用于在tickMark可绘制对象上设置颜色。android:splitTrack
: This expects a boolean value. By default on Android Lollipop and above this