我正在尝试Flutter,我正在尝试更改应用程序上的 BottomNavigationBar
的颜色,但我所能实现的只是更改 BottomNavigationItem
(图标和文本)的颜色 .
这是我宣布 BottomNavigationBar
的地方:
class _BottomNavigationState extends State<BottomNavigationHolder>{
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: null,
body: pages(),
bottomNavigationBar:new BottomNavigationBar(
items: <BottomNavigationBarItem>[
new BottomNavigationBarItem(
icon: const Icon(Icons.home),
title: new Text("Home")
),
new BottomNavigationBarItem(
icon: const Icon(Icons.work),
title: new Text("Self Help")
),
new BottomNavigationBarItem(
icon: const Icon(Icons.face),
title: new Text("Profile")
)
],
currentIndex: index,
onTap: (int i){setState((){index = i;});},
fixedColor: Colors.white,
),
);
}
之前我以为我通过在我的主应用主题上将 canvasColor
编辑为绿色来弄明白,但它搞砸了整个应用程序配色方案:
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
canvasColor: Colors.green
),
home: new FirstScreen(),
);
}
}
2 Answers
尝试将
BottomNavigationBar
包裹在Container
中,然后设置color
.例:
没有选项可以指定
BottomNavigationBar
的背景颜色,但可以更改canvasColor
. 在不弄乱整个应用程序的情况下,您可以实现它的一种方法是将BottomNavigationBar
包装在Theme
中,并且需要canvasColor
.例:
希望有所帮助!