You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Jetpack Compose实现带上下双阴影的立体感按钮?

求助:Jetpack Compose实现双层阴影立体感按钮效果不符问题

我需要用Jetpack Compose实现带有立体感的按钮,该按钮包含顶部黑色阴影和底部白色阴影,预期效果如下:

预期按钮效果

以下是该按钮在Figma中的设计说明:

Figma设计说明

我尝试实现的代码如下:

@Composable
fun GameCoinsView(
  modifier: Modifier = Modifier,
  coins: Int,
  onClick: () -> Unit = {},
) {
  Box(
    modifier = modifier
      .clip(shape = shape)
      .width(IntrinsicSize.Min)
      .height(IntrinsicSize.Min)
  ) {
    Spacer(
      modifier = Modifier
        .align(Alignment.BottomCenter)
        .fillMaxWidth()
        .fillMaxHeight(fraction = 0.95f)
        .shadow(
          elevation = 2.dp,
          shape = RoundedCornerShape(12.dp),
          spotColor = Color.White.copy(alpha = 0.08f),
        ),
    )
    Spacer(
      modifier = Modifier
        .align(Alignment.TopCenter)
        .fillMaxWidth()
        .fillMaxHeight(fraction = 0.95f)
        .shadow(
          elevation = 2.dp,
          shape = RoundedCornerShape(12.dp),
          spotColor = Color.Black.copy(alpha = 0.28f),
        ),
    )
    Spacer(
      modifier = Modifier
        .fillMaxSize()
        .background(color = Color.White.copy(alpha = 0.08f))
        .blur(40.dp),
    )

    Text(
      modifier = Modifier.padding(vertical = 8.dp, horizontal = 12.dp),
      text = NumberFormat.getNumberInstance(ViewUtils.getDefaultLocaleCompose()).format(coins),
      fontSize = 18.sp,
      lineHeight = 23.4.sp,
      fontWeight = FontWeight.W600,
    )
  }
}

实际运行结果如下:

实际运行效果

目前实现效果与预期不符,请求帮助解决该问题。

内容的提问来源于stack exchange,提问作者Ильин Павел

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 22:13:13