2010-09-05 49 views

回答

3

隨着一些挖掘,我發現如何提供一個自定義的Drawable拇指。這是一個可以幫助他人的節選。

ShapeDrawable thumb = new ShapeDrawable(new RectShape()); 
    thumb.getPaint().setColor(0x00FF00); 
    thumb.setIntrinsicHeight(80); 
    thumb.setIntrinsicWidth(30); 
    mySeekBar.setThumb(thumb); 
2

這是一箇舊帖子,但我發現這是谷歌。所以這裏是我的解決方案:

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); 
}