1

How can I specify a textSize for all text elements within a Column / Row?

I have difficulty finding a method, which helps me doing something like the UnspecifiedFontSize (pseudo code):

Row {
    UnspecifiedFontSize(size= 128.dp) {
            Text("ping")
            Text("pong")
        }
    }
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Florian Reisinger
  • 2,638
  • 4
  • 23
  • 34

2 Answers2

5

see androidx/compose/material/Text.kt#110 you can use LocalTextStyle

@Composable
fun Text114514() {
    CompositionLocalProvider(
        LocalTextStyle provides TextStyle(fontSize = 80.sp)
    ) {
        Row {
            Text("ping")
            Text("pong")
        }
    }
}

image

lisonge
  • 429
  • 4
  • 9
2

You can merge the default TextStyle with your custom fontSize using:

CompositionLocalProvider(
    LocalTextStyle provides LocalTextStyle.current.copy(fontSize = 128.dp)
) {
    Row {
        Text("ping")
        Text("pong")
    }
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841