飘动导航栏颜色
最编程
2024-03-30 17:28:40
...
Flutter中导航栏的颜色可以通过AppBar
的backgroundColor
属性来设置。以下是一个简单的示例代码:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My App'),
backgroundColor: Colors.blue, // 设置导航栏颜色为蓝色
),
body: Center(
child: Text('Hello, world!'),
),
),
);
}
}
在这个示例中,我们将导航栏的颜色设置为蓝色。你可以使用任何你喜欢的颜色来代替Colors.blue
,例如Colors.red
、Colors.green
等。
另外,如果你想要更改状态栏的颜色,可以使用SystemChrome.setSystemUIOverlayStyle()
方法,例如:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.blue, // 设置状态栏颜色为蓝色
));
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My App'),
backgroundColor: Colors.blue, // 设置导航栏颜色为蓝色
),
body: Center(
child: Text('Hello, world!'),
),
),
);
}
}
在这个示例中,我们使用SystemChrome.setSystemUIOverlayStyle()
方法设置了状态栏的颜色为蓝色。
上一篇: 蓝色箭头间隔 css 导航菜单代码
下一篇: 蓝色安全色的含义