Drawing Text with a Font

Once we have our font, we set it as the Typeface of a Paint instance: paint.setTypeFace(font);

Via the Paint instance, we also specify the size we want to render the font at: paint.setTextSize(30);

The documentation of this method is again a little sparse. It doesn't tell whether the text size is given in points or pixels. We just assume the latter.

Finally, we can draw text with this font via the following Canvas method: canvas.drawText("This is a test!", 100, 100, paint);

The first parameter is the text to draw. The next two parameters are the coordinates where the text should be drawn to. The last argument is familiar to us: it's the Paint instance that specifies the color, font, and size of the text to be drawn. By setting the color of the Paint, you also set the color of the text to be drawn.

0 0

Post a comment