android disable seek bar for audio controller

Viewed 7961

I used the following seek bar for displacing the progress of my audio.

<SeekBar
    android:padding="7dp"
    android:id="@+id/SeekBar01"
    android:layout_width="245dip"
    android:thumb="@drawable/seekthumb2"
    android:progressDrawable="@drawable/seekbar1"
    android:layout_height="fill_parent"
    android:clickable="false"
    android:focusable="false"

    android:longClickable="false"/>

I want to disable the manual motion of this seek bar. i mean the seek can only move by my code and it cannot be accessed by any other means (Touch).

4 Answers

Just add touch event handler and return true, like example below:

    seekBar.setOnTouchListener(new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

User won't be able to touch and change the progress this way.

Kotlin lambda solution:

seekbar.setOnTouchListener { _, _ -> true }

Try this

seekBar.setEnabled(false);
Related