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
CodePudding user response:
you can use TextStyle.copy
Like this
var style = MaterialTheme.typography.body2.copy(color = Color.Red)