flutter 如何实现自定义导航栏 类似今日头条的头部底部导航
int _selectedIndex = 1;
final _widgetOptions = [
Text('Index 0: Home'),
Text('Index 1: Business'),
Text('Index 2: School'),
];
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
backgroundColor: Colors.grey,
bottom: new TabBar(
controller: controller,
tabs: <Tab>[
new Tab(icon: new Icon(Icons.arrow_forward)),
new Tab(icon: new Icon(Icons.arrow_downward)),
new Tab(icon: new Icon(Icons.arrow_back)),
]
)
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),
BottomNavigationBarItem(icon: Icon(Icons.business), title: Text('Business')),
BottomNavigationBarItem(icon: Icon(Icons.school), title: Text('School')),
],
currentIndex: _selectedIndex,
fixedColor: Colors.deepPurple,
onTap: _onItemTapped,
),
);
}
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
5 回答1.4k 阅读
4 回答1.5k 阅读✓ 已解决
4 回答1.3k 阅读✓ 已解决
3 回答2.6k 阅读✓ 已解决
5 回答1.6k 阅读✓ 已解决
1 回答2.6k 阅读✓ 已解决
2 回答882 阅读✓ 已解决
你的意思是不是小图标自定义?如果是的话给你一个方案!
原理很简单,icon不是一定是Icon,可以是Container,也可以是images