SeekBar禁止点击更改进度

public class Slider extends SeekBar {
private Drawable mThumb;

    public MySeekBar(Context context) {
        super(context);

    }

    public MySeekBar(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    @Override
    public void setThumb(Drawable thumb) {
        super.setThumb(thumb);
        mThumb = thumb;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {

            if (event.getX() >= mThumb.getBounds().left
                    && event.getX() <= mThumb.getBounds().right
                    && event.getY() <= mThumb.getBounds().bottom
                    && event.getY() >= mThumb.getBounds().top) {

                super.onTouchEvent(event);
            } else {
                return false;
            }
        } else if (event.getAction() == MotionEvent.ACTION_UP) {
            return false;
        } else {
            super.onTouchEvent(event);
        }

        return true;
    }
}

你可能感兴趣的:(android)