Show Text Over Android SeekBar Track

625 views Asked by At

I want to show some static text over seek bar track. It's different from what's normally required, i.e., showing current progress as tip or inside thumb.

I've tried both options of showing text; By adding a TextView over seekbar or by adding it dynamically in onDraw() method of my custom seekbar class.

NORMAL VIEW: Seekbar

PROBLEM VIEW: Text appearing over thumb

The issue is that the text is ABOVE both track and seekbar (as shown above). I somehow want to decrease the z-index of text so that it hides behind the thumb.

I'm overriding the onDraw method like:

@Override
protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    paint.getTextBounds(text, 0, text.length(), bounds);
    paint.setTextSize(36);
    int x = getWidth() / 2 - bounds.centerX();
    int y = getHeight() / 2 - bounds.centerY();
    canvas.drawText(text, x, y, paint);
}

Is there a way I can hide text behind thumbnail? Any help is greatly appreciated.

0

There are 0 answers