appbar如何设置成透明的?

设置了backgroundColor为Colors.transparent,阴影也设置为0之后,居然还有一层白色不明view,有大神知道怎么去的吗?

阅读 20.5k
6 个回答
新手上路,请多包涵

elevation必须设置成0 才有效!

新手上路,请多包涵

还需给Scaffold设置透明背景才能去除白色

Scaffold(
    backgroundColor: Colors.transparent,
    appBar: AppBar(
        backgroundColor: Colors.transparent,
        ...
        )
    ...
新手上路,请多包涵

如果你一定要透明,为啥不去掉appbar呢?
用widget手动创建title和backbutton或者actions来模拟appbar也是很容易的啊

新手上路,请多包涵

不是你的appBar没有变透明,而是它已经透明了,但是Scaffold是有背景色的。Scaffold默认背景色就是画布颜色,dark主题是Colors.grey[850],light主题是Colors.grey[50]。你可以给Scaffold加一个backgroundColor,会发现appBar背景色也会跟着变化。

新手上路,请多包涵
Scaffold(
    appBar: AppBar(
      title: const Text('Next page'),
      backgroundColor: Colors.transparent,
      elevation: 0,
    )
新手上路,请多包涵
Scaffold(
 appBar: AppBar(
  elevation: 0,
     backgroundColor: Colors.transparent,
               ),
        )

或者

Scaffold(
 appBar: AppBar(
     shadowColor: Colors.transparent,
     backgroundColor: Colors.transparent,
               ),
        )

将elevation设置为0,elevation默认是4
或者
backgroundColor设置为透明,backgroundColor默认为FF000000

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题