Reputation: 250
how can i change the opacity of Text Color.White in JetPack Compose
Text(text = funfact , fontSize = 18.sp, color = Color.White )
Upvotes: 13
Views: 14446
Reputation: 2065
You can change the alpha channel from the Color attribute:
Text(text = funfact, fontSize = 18.sp, color = Color.White.copy(alpha = 0.5f))
Upvotes: 26
Reputation: 17725
You can also use the alpha
modifier:
Text(
text = funfact,
modifier = Modifier.alpha(0.5f),
fontSize = 18.sp,
color = Color.White,
)
Upvotes: 11
Reputation: 4030
If you want to set alpha for a Text using Material Design standards, a more direct and similar way to @ReVs answer is:
Text(text = "Your text", modifier = Modifier.alpha(ContentAlpha.medium))
Hope it helps!
Upvotes: 4
Reputation: 77
Insert the text component inside a CompositionLocalProvider
as follows:
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
Text(text = "Your text")
}
ContentAlpha
contains 3 default types of opacity: medium, high and disabled.
Tested on stable version of Compose 1.3.1.
Upvotes: 3