0

can anyone help me create a progress bar with a styling like this one:

enter image description here

I know this is a common question and solution can be found, but I didnt saw a progress bar with the progress heigher than the other part.

So can someone help me create this?

Darko Petkovski
  • 3,892
  • 13
  • 53
  • 117

1 Answers1

0

So wih the help of @pskink's code, I've managed to create a solution for this issue. So here is the code and I hope it will help someone in the future!

public class ProgressDrawable extends Drawable {
    private final int mForeground;
    private final int mBackground;
    private final Paint mPaint = new Paint();
    private final RectF mSegment = new RectF();

    public ProgressDrawable(int fgColor, int bgColor) {
        mForeground = fgColor;
        mBackground = bgColor;
    }

    @Override
    protected boolean onLevelChange(int level) {
        invalidateSelf();
        return true;
    }

    @Override
    public void draw(Canvas canvas) {
        float level = getLevel() / 10000f;
        Rect b = getBounds();

        float gapWidth = b.height();
        float segmentWidth = b.width();
        mSegment.set(0, 0, segmentWidth * level, b.height());
        mPaint.setColor(mForeground);

        mSegment.set(0, b.height() / 3, segmentWidth, b.height() - (b.height() / 3));
        mPaint.setColor(mBackground);
        canvas.drawRect(mSegment.left, mSegment.top, mSegment.right, mSegment.bottom, mPaint);
    }

    @Override
    public void setAlpha(int alpha) {
    }

    @Override
    public int getIntrinsicHeight() {
        return 3;
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}

and usage:

Drawable d = new ProgressDrawable(getActivity().getResources().getColor(R.color.toolbar_text_blue), getActivity().getResources().getColor(R.color.toolbar_text_blue));
                    dataProgress.setProgressDrawable(d);
                    dataProgress.setProgress(percent);
Darko Petkovski
  • 3,892
  • 13
  • 53
  • 117