1

enter image description here

I am trying to draw some text above the thumb of the SeekBar like in the image above. The idea is that when you move the thumb along the SeekBar text is displayed above the thumb. I am able to draw text inside the thumb but when I try and draw it outside the thumb it doesn't work. Below is my code:

public class MainActivity extends Activity {

    SeekBar mybar;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mybar = (SeekBar) findViewById(R.id.seekBar1);

        mybar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

                // add here your implementation
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

                // add here your implementation
            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                int value = seekBar.getProgress();
                String valueString = value + "";

                Paint paint = new Paint();
                paint.setColor(Color.BLACK);
                Bitmap b = Bitmap.createBitmap(600, 600,
                        Bitmap.Config.ARGB_8888);

                Canvas canvas = new Canvas(b);

                canvas.drawText(valueString, 100, 100, paint);
                seekBar.draw(canvas);

            }
        });
    }

}

Do I have to override the onDraw method and do it that way instead?

DMC
  • 1,184
  • 5
  • 21
  • 50

0 Answers0