Seekbar提供有setThumb方法,但是单纯用这个方法是无法实现更新Thumb图片的。参照SeekBar父类AbsSeekBar的源码,了解到setThumb仅仅是把AbsSeekBar的mThumb指向新的Drawable,并没有对新的Thumb的Bounds进行设定,但是在draw时,canvas要根据图像的bounds去画,这就出现了问题,输出了一下bounds的Log,发现新的Thumb的bounds的top和bottom都为0,也就是新Bar的高度为0, 这肯定是画不出来的。所以,你要先确定出新的bounds,这就很简单了。附上一段我自己的代码:
oldRect = readprogress.getThumb().getBounds();//获取原来的Bounds构建一个Rect
drawable = getResources().getDrawable(R.drawable.read_progressbar_button);//新的图片转成drawable对象
drawable.setBounds(oldRect);//为新的图片对象添加Bounds
readprogress.setThumb(drawable);//设置新的图片