Along with the built-in fonts, there is a series of styles that are defined as constants in the Typeface class. These styles can be used to modify one of the built-in fonts through the create method available in the Typeface class. This method returns a new Typeface object that can be used.
Here is the list of styles that are defined in the Typeface class:
Using one of them is fairly straightforward. First we call Typeface.create, passing in the base font and the style we want to apply. We get back a Typeface that we pass into the Paint.setTypeface method, and that's it.
Typeface serif_italic = Typeface.create(Typeface.SERIF, Typeface.ITALIC); paint.setTypeface(serif_italic);
canvas.drawText("Hello", text_x, text_y, paint);
Was this article helpful?