Flutter基础控件:BottomNavigationBar

属性

onTap

点击Item回调事件

currentIndex

当前选择的item下标

elevation

阴影

type

bar 类型:fixed,shifting

Flutter的BottomNavigationBar如果不指定type,则当items小于4个时,类型是fixed,大于或等于4个时,自动变成了shifting

fixedColor

BottomNavigationBar.type为fixed设置fixedColor颜色

backgroundColor

整体背景色

iconSize

Item中图片大小

selectedItemColor

被选择item颜色

unselectedItemColor

未被选择item颜色

selectedIconTheme

被选择icon题主颜色

unselectedIconTheme

未被选择icon题主颜色

selectedFontSize

被选择item字体大小

unselectedFontSize

未被选择item字体大小

selectedLabelStyle

被选择item 文字风格

unselectedLabelStyle

未被选择item 文字风格

showSelectedLabels

被选中的item显示文字,未被选中的item不显示文字

showUnselectedLabels

未被选中的item显示文字,被选中的item不显示文字

void main() => runApp(new MyApp());

//StatelessWidget 无状态widget
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'welcome',
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('首页'),
        ),
        body: new Center(
          child: new IconButton(
            icon: new Icon(Icons.volume_up),
            tooltip: 'Increase volume by 10%',
            onPressed: () {
              // ...
            },
          ),
        ),
        bottomNavigationBar: new BottomNavigationWidget(),
      ),
    );
  }
}

class BottomNavigationWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => BottomNavigationWidgetState();
}

class BottomNavigationWidgetState extends State<BottomNavigationWidget> {
  int _currentIndex = 0;

  List<BottomNavigationBarItem> _barItem = [
    BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
    BottomNavigationBarItem(icon: Icon(Icons.list), title: Text('新闻')),
    BottomNavigationBarItem(icon: Icon(Icons.people), title: Text('我的')),
    BottomNavigationBarItem(icon: Icon(Icons.phone), title: Text('隐私')),
  ];

  @override
  Widget build(BuildContext context) {
    return new BottomNavigationBar(
      items: _barItem,
      currentIndex: _currentIndex,
      onTap: (int index) {
        setState(() {
          _currentIndex = index;
        });
      },
      selectedItemColor: Colors.amber[800],
      unselectedItemColor: Colors.grey,
      selectedFontSize: 12.0,
      type: BottomNavigationBarType.fixed,
    );
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值