Home > Blockchain >  How to declare the text size for all Text fields within a row / column
How to declare the text size for all Text fields within a row / column

Time:11-16

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")
        }
    }

CodePudding user response:

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

CodePudding user response:

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")
    }
}
  • Related