1.setThumb(null)
先将thumb置空或者透明,但实际上,拖动SeekBar时仍旧会有个按压效果,如下图所示

2.setBackground(null)
只需要将背景置空,即不会有按压效果了
3.原因分析
拖动SeekBar显示按压效果,故从onTouchEvent
看起,其中基本上都会调用trackTouchEvent
:
typescript
private void trackTouchEvent(MotionEvent event) {
// 省略部分代码
setHotspot(x, y);
setProgressInternal(Math.round(progress), true, false);
}
注意其中的setHotspot
方法:
java
private void setHotspot(float x, float y) {
final Drawable bg = getBackground();
if (bg != null) {
bg.setHotspot(x, y);
}
}
Debug SeekBar可知,背景为RippleDrawable
,可知按压效果为RippleDrawable
绘制的,故将背景置空(setBackground(null)
)即可生效。