【问题标题】:how to remove shade on compose view?如何删除撰写视图上的阴影?
【发布时间】:2021-04-09 12:04:22
【问题描述】:

我在 android 视图中使用撰写按钮,但底部有一些阴影。如何删除它?

    @Composable
fun VisibilityAnimationFAB() {
    var expanded by remember { mutableStateOf(true) }
    FloatingActionButton(
        onClick = { expanded = !expanded },
        modifier = Modifier
    ) {
        Row(Modifier.padding(start = 16.dp, end = 16.dp)) {
            Icon(
                vectorResource(id = R.drawable.ic_twitter),
                Modifier.align(Alignment.CenterVertically)
            )
            AnimatedVisibility(
                expanded,
                modifier = Modifier.align(Alignment.CenterVertically)
            ) {
                androidx.compose.material.Text(modifier = Modifier.padding(start = 8.dp), text = "Tweet")
            }
        }
    }

}

【问题讨论】:

    标签: android floating-action-button android-jetpack-compose


    【解决方案1】:

    FloatingActionButton 中使用elevation 参数。在材料设计中,高程是沿 z 轴的两个表面之间的相对距离。阴影使表面高程的差异变得明显。 (source)

    您必须传递FloatingActionButtonElevation,可以使用elevation(...) 方法创建。

    FloatingActionButton(
      elevation = elevation(
        defaultElevation = 0.dp
        pressedElevation = 0.dp
      ),
      // ...
    ) {
      // ...
    }
    

    【讨论】:

      【解决方案2】:

      使用1.0.0-beta03,您可以使用:

      FloatingActionButton(
              onClick = { expanded = !expanded },
              modifier = Modifier,
              elevation = FloatingActionButtonDefaults.elevation(0.dp,0.dp)
          )
      

      【讨论】:

        【解决方案3】:

        此代码禁用所有阴影

            FloatingActionButton(
                onClick = { expanded = !expanded },
                modifier = Modifier,
                elevation = null
            )
        

        【讨论】:

          猜你喜欢
          • 2021-11-12
          • 1970-01-01
          • 2020-02-04
          • 1970-01-01
          • 2016-11-23
          • 2013-02-25
          • 2012-12-19
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多