Fast Compose

Lesson 1

Text

Text shows a piece of text on the screen. It's the first composable most people learn.

Show text

Call Text with the string you want to show:

Text is a composable function: a Kotlin function that describes part of the UI. Composable names start with a capital letter.

Size, color and style

Named parameters change how the text looks. Sizes for text use sp, a unit that follows the user's font size setting.

The Column puts the three texts below each other. You'll learn it in the next lesson.

ParameterWhat it doesExample
fontSizeSize of the lettersfontSize = 20.sp
colorColor of the textcolor = Color.Red
fontWeightHow thick the letters arefontWeight = FontWeight.Bold
fontStyleNormal or italicfontStyle = FontStyle.Italic
textAlignAlignment inside its widthtextAlign = TextAlign.Center

Limit the number of lines

Long text wraps onto new lines. To keep it on one line, set maxLines, and use overflow to end it with an ellipsis (…) when it doesn't fit:

Modifier.width(220.dp) gives the text a fixed width. Modifiers change the size, spacing and look of any composable.

Summary