简体   繁体   中英

How can I create a instance of TextStyle based MaterialTheme.typography.body2 and Color.Red when I use Jetpack Compose?

I know I can use Code A to create a instance of TextStyle with color , fontFamily and etc.

Now I hope to get a instance of TextStyle based MaterialTheme.typography.body2 , and I hope that the style has customized color Red .

How can I do? BTW, Code B is wrong.

Code A

var style = TextStyle(
        color = Color.Red
        fontFamily = FontFamily.Default,
        fontWeight = FontWeight.Normal,
        fontSize = 14.sp
    )

Code B

var style: TextStyle = MaterialTheme.typography.body2
style.color=  Color.Red

you can use TextStyle.copy

Like this

var style = MaterialTheme.typography.body2.copy(color = Color.Red)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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