小智 23
如果您使用材质 3,您应该将属性 surfaceTintColor 设置为透明
Dialog(
backgroundColor: MyColors.white,
surfaceTintColor: Colors.transparent,
child: ... )
Run Code Online (Sandbox Code Playgroud)
这对我有用:)
Cop*_*oad 12
您现在可以使用backgroundColor
属性AlertDialog
来更改颜色。
AlertDialog(
backgroundColor: Colors.orange,
...
)
Run Code Online (Sandbox Code Playgroud)
小智 7
你需要用你Dialog
的Builder
这个样子.之后dialogBackgroundColor
会产生影响.
Theme(
data: ThemeData(dialogBackgroundColor: Colors.orange),
child: Builder(
builder: (context) {
return RaisedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("Dialog title"),
);
},
);
},
child: Text("Show dialog"),
);
},
),
)
Run Code Online (Sandbox Code Playgroud)
您现在可以使用AlertDialog 的backgroundColor 属性来更改颜色。
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
backgroundColor: Colors.green,
content: Container(...)
),
}),
Run Code Online (Sandbox Code Playgroud)
您可以在不使用Builder
.
这是示例。
@override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return Theme(
data: Theme.of(context).copyWith(dialogBackgroundColor: Colors.orange),
child: AlertDialog(
title: Text("Dialog Title"),
),
);
},
);
},
child: Text("Show dialog"),
);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18481 次 |
最近记录: |