Most likely, two steps are needed here. you draw a line along the path first with the color for the background, and then draw the text as indicated. Set the line thickness using the paint object. In addition, changing the style of the paint can help with the effect. try FILL , STROKE or FILL_AND_STROKE for different effects.
mpaint.setStyle(Paint.Style.STROKE); mpaint.setStrokeWidth(strokeWidth);
Added a pattern for drawing the path (rectangle) with red color:
Paint mPaint = new Paint(); mPaint.setColor(Color.RED); Path mPath = new Path(); RectF mRectF = new RectF(20, 20, 240, 240); mPath.addRect(mRectF, Path.Direction.CCW); mPaint.setStrokeWidth(20); mPaint.setStyle(Paint.Style.STROKE); canvas.drawPath(mPath, mPaint);
Then draw the text along the same path (blue color):
mPaint.setColor(Color.BLUE); mPaint.setStrokeWidth(0); mPaint.setStyle(Paint.Style.FILL); mPaint.setTextSize(20); canvas.drawTextOnPath("Draw the text, with origin at (x,y), using the specified paint, along the specified path.", mPath, 0, 5, mPaint);

source share