Expounding Android Canvas’ DrawText

Photo by Jason Leung on Unsplash

In Android, when we want to have some Text, we would just use TextView. However, in case we want to have a custom view and have better control of the text, we could use the Canvas' drawText api to draw the text.

Check out the below simple App I made to show some fun with drawText (you could get the code in the below link)

In this blog, I’ll be explaining some drawText features provided.

The function arguments

It consist of 4 arguments.

canvas.drawText(text, coordinateX, coordinateY, paint)
  • The text is just the text in string. There are other similar function which takes in charArray and charSequence.
  • The coordinateX and coordinateY is use to position the text. This is further explained below in the next section
  • The paint to decide how one would draw the text.

The coordinate

If we were to draw the text using coordinate 0, 0 as below

canvas.drawText(text, 0, 0, paint)

--

--