How to draw text on canvas?

Karthick picture Karthick · Oct 28, 2010 · Viewed 77.3k times · Source

i'm trying to develop a simple pie chart class for android. For now, it can take a map of labels and values and draw the pie chart. I'm yet to add the legends for the pie, which is where i need to place the texts near small rectangles on the screen corner. Any help appreciated, since i'm new to Android dev.

Answer

Jean-Philippe Jodoin picture Jean-Philippe Jodoin · Jul 28, 2013

You will have to use the drawText method of the Canvas class.

Paint paint = new Paint(); 
canvas.drawPaint(paint); 
paint.setColor(Color.BLACK); 
paint.setTextSize(16); 
canvas.drawText("My Text", x, y, paint); 

Here's the relevant documentation about it:

http://developer.android.com/reference/android/graphics/Canvas.html#drawText(java.lang.String, float, float, android.graphics.Paint)