简体   繁体   English

将多种样式应用于单个文本 - Jetpack Compose

[英]Apply multiple styles to a single Text - Jetpack Compose

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因为我已经使用了 style 属性

    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 个修饰符,假设我想添加填充和一个 fillMaxWidth

With 1.0.0 for the TestStyle you can use the merge method.对于TestStyle 1.0.0 ,您可以使用merge方法。
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:您可以通过复制来修改TextStyle ,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM