As many Modifiers in Jetpack Compose order of Modifier.shadow()
matters. use shadow first.
Button(
modifier = Modifier
.shadow(2.dp, RoundedCornerShape(2.dp))
.height(36.dp),
onClick = { /*TODO*/ }) {
Text("Button")
}
vs
Button(
modifier = Modifier
.height(36.dp)
.shadow(2.dp, RoundedCornerShape(2.dp)),
onClick = { /*TODO*/ }) {
Text("Button")
}
But this is not how you set elevation for button. This is for demonstrating how Modifier.shadow() order changes outcome, maybe helpful with some Composables but with Button you need to use
Button(
modifier = Modifier.height(36.dp),
shape = RoundedCornerShape(2.dp),
elevation = ButtonDefaults.elevation(...),
onClick = { /*TODO*/ }) {
Text("Button")
}
and elevation function has properties for different states such as
@Composable
fun elevation(
defaultElevation: Dp = 2.dp,
pressedElevation: Dp = 8.dp,
disabledElevation: Dp = 0.dp,
hoveredElevation: Dp = 4.dp,
focusedElevation: Dp = 4.dp,
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.