Skip to content

Instantly share code, notes, and snippets.

@vidyesh95
Created February 14, 2024 21:03
Show Gist options
  • Save vidyesh95/a2bc2022147a4dcfe4b153884e26cc14 to your computer and use it in GitHub Desktop.
Save vidyesh95/a2bc2022147a4dcfe4b153884e26cc14 to your computer and use it in GitHub Desktop.
Compose background shadow for white icon
// Entire Background
Icon(
modifier = Modifier
.align(alignment = Alignment.TopEnd)
.padding(top = 8.dp, end = 6.dp)
.size(24.dp)
.drawBehind {
val shadowColor = Color.Black
.copy(alpha = 0.25f)
.toArgb()
val transparentColor = Color.Transparent.toArgb()
drawIntoCanvas { canvas ->
val paint = Paint()
paint
.asFrameworkPaint()
.apply {
color = transparentColor
setShadowLayer(2f, 0f, 1f, shadowColor)
}
canvas.drawRoundRect(0f, 0f, size.width, size.height, 0f, 0f, paint)
}
},
imageVector = Icons.AutoMirrored.Filled.VolumeOff,
contentDescription = "Volume Off",
tint = Color.White,
)
// Blur Android 12>
Icon(
modifier = Modifier
.align(alignment = Alignment.TopEnd)
.padding(top = 8.dp, end = 6.dp)
.size(24.dp)
.blur(radius = 2.dp),
imageVector = Icons.AutoMirrored.Filled.VolumeOff,
contentDescription = "Volume Off",
tint = Color.Black.copy(alpha = 0.50f),
)
Icon(
modifier = Modifier
.align(alignment = Alignment.TopEnd)
.padding(top = 8.dp, end = 6.dp)
.size(24.dp),
imageVector = Icons.AutoMirrored.Filled.VolumeOff,
contentDescription = "Volume Off",
tint = Color.White,
)
Text(
modifier = Modifier
.align(Alignment.BottomStart)
.padding(start = 8.dp, bottom = 8.dp),
text = "A Record Of Mortal's Journey To Immortality: " +
"Immortal Han Li's Adventure with cyan bottle",
color = Color.White,
style = MaterialTheme.typography.titleSmall.copy(
shadow = Shadow(
color = Color.Black.copy(alpha = 0.95f),
offset = Offset(0f, 1f),
blurRadius = 2f
)
),
softWrap = true,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment