Last active
May 13, 2024 17:27
-
-
Save Oleur/ca70cd08f51568a0b870333c15ffbca3 to your computer and use it in GitHub Desktop.
Draw text on Jetpack Compose Canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val textPaint = Paint().asFrameworkPaint().apply { | |
isAntiAlias = true | |
textSize = 24.sp.toPx() | |
color = android.graphics.Color.BLUE | |
typeface = Typeface.create(Typeface.MONOSPACE, Typeface.BOLD) | |
} | |
Canvas( | |
modifier = modifier.fillMaxSize(), | |
onDraw = { | |
drawIntoCanvas { | |
it.nativeCanvas.drawText( | |
"My Jetpack Compose Text" | |
0f, // x-coordinates of the origin (top left) | |
120.dp.toPx(), // y-coordinates of the origin (top left) | |
textPaint | |
) | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's very little documentation on drawing custom shapes. Thanks for this.