[英]Using .shadow with Button in jetpack compose causes an issue
As many Modifiers in Jetpack Compose order of Modifier.shadow()
matters. Jetpack Compose 中的
Modifier.shadow()
顺序中的许多修饰符很重要。 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
这是为了演示 Modifier.shadow() 顺序如何改变结果,可能对一些 Composables 有帮助,但对于 Button 你需要使用
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,
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.