Reputation: 3958
I'm trying to draw text using canvas. I checked out everywhere but those examples rather complex, I could draw text on canvas but it's not showing like this photo.
I found this code and it's working, I just need to write like above image.
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(30);
paint.setAntiAlias(true);
canvas.drawText("There are 137 days, 9 hours 4 minutes and 36 seconds", 150,150, paint);
Upvotes: 3
Views: 2160
Reputation: 8615
Get the font you would like and add it to your assets folder. Lets say the font file name is "pretty.otf". Then in your code all you have to do is.
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(30);
paint.setAntiAlias(true);
Context mContext = getContext();
Typeface myTypeface = Typeface.createFromAssets(mContext.getAssets(), "pretty.otf");
paint.setTypeface(myTypeface);
To space your text like in the image, add a new line by adding the \n character in your string like this:
canvas.drawTextOnPath("There are\n137 days, 9 Hour\n4 Minutes and 36 seconds\nuntil Christmas", circle, 0,30,paint);
Upvotes: 6