Search code examples
androidtouchprogressseekbar

Android: Change SeekBar Behavior


I want my SeekBar to only change progress when the thumb is dragged. Right now it also changes position when anywhere on the progress bar is clicked. Is there a way to remove that extra functionality?


Solution

  • I suppose you could use SeekBar.getThumbOffset along with SeekBar.getProgress in the onStartTrackingTouch method to filter touch events that don't lie in that area using a touch listener:

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int x = (int)event.getX();
        int y = (int)event.getY();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_UP:
        }
    return false;
    }
    

    Is there an easy way? I don't think so.