flutter BottomNavigationBarItem设置字体颜色
时间: 2024-05-20 18:07:27 浏览: 13
在Flutter中,可以通过设置BottomNavigationBarItem的属性来设置字体颜色。具体步骤如下:
1. 首先,创建一个BottomNavigationBar,其中包含多个BottomNavigationBarItem。每个BottomNavigationBarItem代表一个底部导航栏的选项。
2. 在创建BottomNavigationBarItem时,可以使用selected和unselected属性来设置选中和未选中状态下的字体颜色。
下面是一个示例代码:
```dart
BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
// 设置未选中状态下的字体颜色
unselectedLabelStyle: TextStyle(color: Colors.grey),
// 设置选中状态下的字体颜色
selectedLabelStyle: TextStyle(color: Colors.blue),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
unselectedLabelStyle: TextStyle(color: Colors.grey),
selectedLabelStyle: TextStyle(color: Colors.blue),
),
BottomNavigationBarItem(
icon: Icon(Icons.person), label: 'Profile',
unselectedLabelStyle: TextStyle(color: Colors.grey),
selectedLabelStyle: TextStyle(color: Colors.blue),
),
],
)
```
在上面的代码中,我们通过unselectedLabelStyle和selectedLabelStyle属性分别设置了未选中和选中状态下的字体颜色。