Style BottomNavigationBar in Flutter

前端 未结 9 654
醉话见心
醉话见心 2020-12-12 19:22

I am trying out Flutter and I am trying to change the colour of the BottomNavigationBar on the app but all I could achieve was change the colour of the Bo

相关标签:
9条回答
  • 2020-12-12 19:41

    The accepted answer isn't entirely wrong. However, BottomNavigationBar does in-fact have a property of backgroundColor. As per the documentation

    If type is BottomNavigationBarType.shifting and the itemss, have BottomNavigationBarItem.backgroundColor set, the item's backgroundColor will splash and overwrite this color.

    What this means is that the BottomNavigation's backgroundColor will be overriden by the individual items backgroundColor because the default type is BottomNavigationBarType.shifting.

    To fix this, simply add the following property to the declared BottomNavigationbar widget.

    type: BottomNavigationBarType.fixed,
    

    Note: If you do, however, want the shifting effect you will have to declare colors for each item, or wrap the widget that allows the overriding of the child widget(s) background color.

    i.e Something like Container widget.

    0 讨论(0)
  • 2020-12-12 19:48

    You can currently style them BottomNavigationBar directly from the Theme, like this:

    ThemeData(
         
          bottomNavigationBarTheme: BottomNavigationBarThemeData(
            backgroundColor: Colors.grey[900],
            elevation: 10,
            selectedLabelStyle: TextStyle(
                color: Color(0xFFA67926), fontFamily: 'Montserrat', fontSize: 14.0),
            unselectedLabelStyle: TextStyle(
                color: Colors.grey[600], fontFamily: 'Montserrat', fontSize: 12.0),
            selectedItemColor: Color(0xFFA67926),
            unselectedItemColor: Colors.grey[600],
            showUnselectedLabels: true,
          ),
    

    )

    0 讨论(0)
  • 2020-12-12 19:49

    Set following properties to change the background, selected and unselected colors

    bottomNavigationBar: BottomNavigationBar(
            backgroundColor: Colors.blue,
            selectedItemColor: Colors.black,
            unselectedItemColor: Colors.white,
            type: BottomNavigationBarType.fixed,
            ...
    )
    
    0 讨论(0)
提交回复
热议问题