首页 文章

BottomNavigationBarItem中添加的四个图标不起作用

提问于
浏览
1

当我尝试添加四个图标时,我是新来的,我创建了一个底部导航栏 . 图标颜色变为白色 . 我怎么能实现这一点,任何人都可以建议我 . 以下是我的代码 . 任何帮助将不胜感激 .

bottomNavigationBar: new BottomNavigationBar(items: [
    new BottomNavigationBarItem(icon: new Icon(Icons.add), title: new Text("Text")),
    new BottomNavigationBarItem(icon: new Icon(Icons.person), title: new Text("Contact")),
    new BottomNavigationBarItem(icon: new Icon(Icons.accessibility), title: new Text("Acess")),
    new BottomNavigationBarItem(icon: new Icon(Icons.account_balance), title: new Text("Balance"))
  ]),

1 回答

  • 1

    如果有3个以上的元素,则需要显式设置 type: BottomNavigationBarType.fixed,

    bottomNavigationBar: new BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        items: [
        new BottomNavigationBarItem(icon: new Icon(Icons.add), title: new Text("Text")),
        new BottomNavigationBarItem(icon: new Icon(Icons.person), title: new Text("Contact")),
        new BottomNavigationBarItem(icon: new Icon(Icons.accessibility), title: new Text("Acess")),
        new BottomNavigationBarItem(icon: new Icon(Icons.account_balance), title: new Text("Balance"))
      ]),
    

    当提供超过3个BottomNavigationBar项时,如果未指定类型,则根据https://docs.flutter.io/flutter/material/BottomNavigationBar/BottomNavigationBar.html更改为BottomNavigationBarType.shifting .

相关问题