我選擇和未選擇的 BottomNavigationBarItems 標簽的顏色沒有改變......我嘗試了很多方法,比如
selectedItemColor: Colors.blue,
unselectedItemColor: Colors.black,
和
unselectedLabelStyle: const TextStyle(color: Colors.grey, fontSize: 14),
selectedLabelStyle: const TextStyle(color: Colors.blue, fontSize: 14),
等等。我究竟做錯了什么?這是代碼:
class RandomWordsState extends State<RandomWords> {
var _currentIndex = 0;
var _pageList = [HomePage(), RecommendPage(), PersonalPage()];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('APPBAR'),
centerTitle: true,
elevation: 10,
),
//body: this._pageList[this._currentIndex],
body: IndexedStack(index: _currentIndex, children: _pageList,),
bottomNavigationBar: BottomNavigationBar(
selectedItemColor: Colors.blue,
unselectedItemColor: Colors.black,
//unselectedItemColor: Colors.black,
//selectedItemColor: Colors.blue,
//selectedLabelStyle: TextStyle(fontSize: 22),
//selectedItemColor: Colors.red,
//fixedColor: Colors.blue,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(
Icons.home,
//color: _currentIndex == 0 ? Colors.blue : Colors.grey,
),
label: "A",
),
BottomNavigationBarItem(
label: "B",
icon: Icon(
Icons.recommend,
//color: _currentIndex == 1 ? Colors.blue : Colors.grey,
),
),
BottomNavigationBarItem(
icon: Icon(
Icons.person,
//color: _currentIndex == 2 ? Colors.blue : Colors.grey,
),
label: "C",
)
],
onTap: (value){
setState(() {
this._currentIndex = value.toInt();
});
},
// unselectedLabelStyle: const TextStyle(color: Colors.grey, fontSize: 14),
// selectedLabelStyle: const TextStyle(color: Colors.blue, fontSize: 14),
type: BottomNavigationBarType.fixed,
),
);
}
}
或者,另一方面,有什么方法可以更改 BottomNavigationBarItem 中標簽的顏色?謝謝。
uj5u.com熱心網友回復:
您需要提供currentIndexonBottomNavigationBar才能看到效果。
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
更多關于底部導航欄。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/420284.html
標籤:
