The equivalent to iOS' CoreText in Android is the drawText
APIs, part of the Canvas class, Canvas.drawText()
, Canvas.drawPosText()
, etc. see javadoc for Canvas for more detail. These graphics APIs use Skia underneath.
The functionalities that these graphics APIs provide are not the same as those in iOS, say there's no CTFramesetter
equivalent that helps you layout text and handle line breaks for you. With the drawText
APIs, you can only draw one line at a time, you will have to handle line breaks yourself, It is like using CTTypesetter
in iOS. For laying out text, see Paint.breakText
and Paint.measureText
.
For changing font size & font face, you can set related attributes in the Paint
object, which is passed as the last parameter to the drawText
APIs.
Snippet:
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(14);
String text = "Hello world!";
canvas.drawText(text, 0, 100, paint);
Note: The coordinate system used in the Android drawText
APIs is from left-top
corner.