Apply multiple styles to a single Text - Jetpack Compose

Viewed 2838

I want to know if there is a way to apply multiple styles to a text, here I apply a material theme to this text, but I also want to change this text size, how can I do it ? since I have already used the style attribute

    Text(text = "This is my default text", style = (MaterialTheme.typography).body1)

Also, how to add 2 modifiers , lets say I want to add padding and also a fillMaxWidth

2 Answers

With 1.0.0 for the TestStyle you can use the merge method.
Also if you want to use multiple modifiers you can concatenated them. In this case the order affects the final result.

Example:

   Text(text = "This is my default text",
           style = (MaterialTheme.typography).body1
                   .merge(TextStyle(fontSize = 20.sp)),
           modifier = Modifier.padding(start = 16.dp).fillMaxWidth()
   )

You can modify a TextStyle by copying it, for example:

Text(
    text = "This is my default text",
    style = MaterialTheme.typography.body1.copy(
        fontSize = 10.sp
    )
)
Related