Skip to content
Advertisement

Android Kotlin – Why does a Seekbar minimum value over 100 not work?

Hello everybody When i add a min value to my Seekbar which is over 100 it always shows an min value of 100. So for example my min value is 120 but it shows 120. I found out that i can use every value until 100 but no bigger value for my “min”. Does anyone know the reason?

My code:

        myseekbar.min = 120
    myseekbar.max = 200
    
    myseekbar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener{
        override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
        }

        override fun onStartTrackingTouch(seekBar: SeekBar?) {
        }

        override fun onStopTrackingTouch(seekBar: SeekBar?) {
        }
    })

Advertisement

Answer

seekbar.min = 120

Requires, API level 26 and above. If you test in a API level 26+, it should work fine. Below is my code :

Kotlin

seekbar.max = 200
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    seekbar.min = 120
}

seekbar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener{
    override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
        seekbarValue.text = p1.toString()
    }
    override fun onStartTrackingTouch(p0: SeekBar?) {}

    override fun onStopTrackingTouch(p0: SeekBar?) {}
})

XML

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <SeekBar
        android:id="@+id/seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@+id/seekbar_value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

Output:

Minimum

Maximum

Advertisement