[英]how to change the opacity of the snackbar in flutter?
I wish to change the opacity of the SnackBar.我希望更改 SnackBar 的不透明度。 It has only the background property.它只有背景属性。 Can it be customized or I have to create the custom widget for snack bar?可以自定义还是我必须为小吃店创建自定义小部件?
Try using the color property of snack bar like this, 尝试使用像这样的小吃店的颜色属性,
backgroundColor: Colors.black.withOpacity(0.5)
This should work as you expected. 这应该按照您的预期工作。
You can adjust the opactiy of your backgroundColor
with 您可以使用调整backgroundColor
的opactiy
color.withAlpha(..)
, color.withAlpha(..)
,
color.withOpacity(..)
, color.withOpacity(..)
,
using a hexadecimal integer 0x33ffffff
(the first pair of digits after the x
represents the alpha value), 使用十六进制整数0x33ffffff
( x
0x33ffffff
的第一对数字代表alpha值),
creating a Color
using Color.fromARGB(...)
使用Color.fromARGB(...)
创建Color
or by using Color.fromRGBO(...)
. 或者使用Color.fromRGBO(...)
。
You can find information about this on this documentation page about the Color
class . 您可以在此文档页面上找到有关Color
类的信息 。
Now, you face the following problem : Your content is not yet translucent. 现在,您遇到以下问题 :您的内容尚未透明。
This is easily adjustable using the Opcacity
Widget. 使用Opcacity
Widget可以轻松调整。
In your Snackbar
just surround your actual content
with an Opacity
Widget: 在您的Snackbar
,使用Opacity
Widget Snackbar
您的实际content
:
SnackBar(backgroundColor: Color(0x66bbbbbb),
content: Opacity(opacity: .7,
child: Container(), // your content
),
)
If you are planning to make the background transparent, this may help you.如果您打算使背景透明,这可能对您有所帮助。 Mostly you get a black background because of elevation.大多数情况下,由于海拔的原因,您会得到黑色背景。
SnackBar(
elevation: 0,
backgroundColor: Colors.transparent,
/.......
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.