Hassaan
10/27/2022, 11:26 AMText(
text = "Hello world!",
fontSize = 44.sp, // ist time
style = TextStyle(
fontSize = 24.sp, // ist time
shadow = Shadow(
color = Color.Magenta,
offset = offset,
blurRadius = 3f
)
)
)
Stylianos Gakis
10/27/2022, 11:37 AMPriyank
10/27/2022, 11:45 AMFor ease of use, commonly used parameters from TextStyle are also present here. The order of precedence is as follows:
• If a parameter is explicitly set here (i.e, it is not null or TextUnit.Unspecified), then this parameter will always be used.
• If a parameter is not set, (null or TextUnit.Unspecified), then the corresponding value from style will be used instead.
Valentin Gusselnikov
10/27/2022, 11:46 AMText
and see how it works under the hood. Basically it merges parameters with style
. And parameters have higher "priority".mattinger
10/27/2022, 5:51 PMSurface {
Text(text="foo")
}
The surface will have a background color of MaterialTheme.colors.surface
and by default any content you have (text or icons) would have a color of MaterialTheme.colors.onSurface
This allows for icons and text to always be properly visible when used on a surface. In fact, various containers do similar things settings these default color and alpha values.
If you have a color in your TextStyle or give one to the Text function, you are overriding those defaults. And if done incorrectly can lead to some visual issues.mattinger
10/27/2022, 5:54 PMText(style=MaterialTheme.typography.body1)
Unless you have a real need to color something, let the container you are using determine the color of your text.mattinger
10/27/2022, 5:55 PM