user1276092
user1276092

Reputation: 513

How to display arc in android with Text

I need to display an arc in android with text in it. Lets say Text should be in white color where as the arc should be filled with Red background. I got succeeded in displaying the text in arc by using addArc() method, but not able to fill the arc's background. I used the following code in my onDraw() method:

path = new Path();
path.addArc(rect, 0, 60); 
paint6 = new Paint(Paint.ANTI_ALIAS_FLAG); 
paint6.setStyle(Paint.Style.FILL_AND_STROKE); 
paint6.setColor(Color.BLACK);
paint6.setTextSize(20f);
paint2.setStrokeWidth(mRadius/2);
paint2.setStrokeCap(Paint.Cap.BUTT);
canvas.drawTextOnPath("Hello", path, 0, 20, paint6);

Can anyone help me in sorting out this issue?

Upvotes: 2

Views: 1502

Answers (1)

user1276092
user1276092

Reputation: 513

I found the answer myself

     Paint mPaint = new Paint();
    mPaint.setColor(Color.GREEN);
    Path mPath = new Path();
    mPath.addArc(rect, 0, 60);
    mPaint.setStrokeWidth(mRadius/2);
    mPaint.setStyle(Paint.Style.STROKE);
    canvas.drawPath(mPath, mPaint);

    mPaint.setColor(Color.BLUE);
    mPaint.setStrokeWidth(mRadius/2);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setTextSize(20);
    canvas.drawTextOnPath("Draw ", mPath, 0, 20, mPaint);

Upvotes: 3

Related Questions