textAlign
is only responsible for horizontal alignment, usually to control vertical alignment you can use a container.
I like to use a technique where you add an invisible view that gives the layout some size guides, and then place the actual view using the parent alignment.
In this case, the blank text with minLines
will take the necessary height, and the actual text will be centered in the box.
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.background(Color.Black)
) {
Text("", minLines = 3)
Text(
"Centered vertically",
textAlign = TextAlign.Center,
color = Color.White,
)
}
