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.
| Parameter | What it does | Example |
|---|---|---|
fontSize | Size of the letters | fontSize = 20.sp |
color | Color of the text | color = Color.Red |
fontWeight | How thick the letters are | fontWeight = FontWeight.Bold |
fontStyle | Normal or italic | fontStyle = FontStyle.Italic |
textAlign | Alignment inside its width | textAlign = 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
Text("…")shows text.- Named parameters like
fontSize,colorandfontWeightstyle it. maxLinesandoverflowcontrol long text.
Fast Compose