Henrique Henrique - 1 year ago 94
Android Question

Detecting thumb position in SeekBar prior to API version 16

Basically, I need to detect when the progress changes in the SeekBar and draw a text view on top of the thumb indicating the progress value.

I do this by implementing a


and on the
public void onProgressChanged(SeekBar seekBar, int progress, boolean b)
method, I call
Rect thumbRect = seekBar.getThumb().getBounds();
to determine where the thumb is positioned.

This works perfectly fine, but apparently
is only available in API level 16+ (Android 4.1), causing a
on earlier versions.

Any idea how to work around this issue?

Answer Source

I was able to use my own class to get the Thumb:


package mobi.sherif.seekbarthumbposition;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.SeekBar;

public class MySeekBar extends SeekBar {

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

    Drawable mThumb;
    public void setThumb(Drawable thumb) {
        mThumb = thumb;
    public Drawable getSeekBarThumb() {
        return mThumb;


In the activity this works perfectly:

package mobi.sherif.seekbarthumbposition;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class MainActivity extends Activity implements OnSeekBarChangeListener {
    MySeekBar mSeekBar;
    protected void onCreate(Bundle savedInstanceState) {
        mSeekBar = (MySeekBar) findViewById(R.id.seekbar);
    public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
        Rect thumbRect = mSeekBar.getSeekBarThumb().getBounds();
        Log.v("sherif", "(" + thumbRect.left + ", " + thumbRect.top + ", " + thumbRect.right + ", " + thumbRect.bottom + ")");
    public void onStartTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub

    public void onStopTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download