How do I get the thumb of an Android SeekBar to ma

2019-01-24 22:21发布

Do I need to implement a custom thumb Drawable?

2条回答
forever°为你锁心
2楼-- · 2019-01-24 22:50

It's an old post, but I found this from google. so here's my solution:

Drawable thumb; //load this earlier.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    thumb = getContext().getResources().getDrawable(R.drawable.slider_thumb);
}

private void expandThumb(int height) {
    thumb.setBounds(0, 0, thumb.getIntrinsicWidth(), height); 
    //force a redraw
    int progress = getProgress();
    setProgress(0);
    setProgress(progress);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    expandThumb(h);
}
查看更多
男人必须洒脱
3楼-- · 2019-01-24 22:52

With some digging, I found how to supply a custom Drawable thumb. Here's an excerpt that may help others.

  ShapeDrawable thumb = new ShapeDrawable( new RectShape() );
  thumb.getPaint().setColor( 0x00FF00 );
  thumb.setIntrinsicHeight( 80 );
  thumb.setIntrinsicWidth( 30 );
  mySeekBar.setThumb( thumb );
查看更多
登录 后发表回答