Kevin S
05/21/2025, 2:35 PMimport androidx.compose.material3.Button
@Composable
@Preview
private fun Test() {
Box(Modifier.background(Color.Yellow)) {
Button(
onClick = { },
enabled = true,
modifier = Modifier.background(Color.Red),
) {
Text("Hello")
}
}
}
If you look at the image, there's a large amount of red vertically around the button. Why is this? Is there a way to have it actually wrap the button? If I update the height it goes away, but id rather shrink the padding instead.Mark
05/21/2025, 3:34 PMLocalMinimumInteractiveComponentSize
? If so, then you can override that.Louis Pullen-Freilich [G]
05/21/2025, 3:59 PMKevin S
05/21/2025, 4:02 PMLouis Pullen-Freilich [G]
05/21/2025, 4:18 PMKevin S
05/21/2025, 4:39 PMLouis Pullen-Freilich [G]
05/21/2025, 4:43 PMSeri
05/21/2025, 4:54 PMgraphicsLayer
modifier on your box layout? https://developer.android.com/develop/ui/compose/graphics/draw/modifiers#graphicsLayerLouis Pullen-Freilich [G]
05/21/2025, 5:04 PMSeri
05/21/2025, 5:08 PMKevin S
05/21/2025, 8:19 PMprivate fun Modifier.addButtonShadow(
cornerRadiusDp: Dp,
shadowColor: Color,
shadowHeight: Dp,
) =
this.drawWithContent {
val cornerRadius = CornerRadius(cornerRadiusDp.toPx(), cornerRadiusDp.toPx())
val roundedRectanglePath = Path().apply {
addRoundRect(
RoundRect(
left = -1f,
top = -shadowHeight.toPx(),
right = size.width + 1,
bottom = size.height - shadowHeight.toPx(),
topLeftCornerRadius = cornerRadius,
topRightCornerRadius = cornerRadius,
bottomLeftCornerRadius = cornerRadius,
bottomRightCornerRadius = cornerRadius
)
)
}
drawContent()
clipPath(roundedRectanglePath, clipOp = ClipOp.Difference) {
drawRoundRect(
shadowColor,
topLeft = Offset(0f, 0f),
size = size,
cornerRadius = cornerRadius
)
}
}
This is without the extra paddingColton Idle
05/21/2025, 10:13 PM