[英]Why am I not able to change the background color of my bottom navigation bar in Flutter?
我想將底部導航欄的背景顏色更改為黑色,但它仍然是白色。 是什么導致了這個問題?
底部導航欄截圖
底部導航條碼。
bottomNavigationBar: BottomNavigationBar(
onTap: _onItemTapped,
type: BottomNavigationBarType.shifting,
iconSize: 30,
unselectedItemColor: Colors.black,
selectedIconTheme: const IconThemeData(color: Colors.black, size: 30),
selectedItemColor: Colors.black,
selectedLabelStyle: const TextStyle(fontWeight: FontWeight.bold),
backgroundColor: Colors.white,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.door_back_door),
label: 'Rooms',
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
),
BottomNavigationBarItem(
icon: Icon(Icons.map),
label: 'Maps',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
],
currentIndex: _selectedIndex,
),
我一直在努力弄清楚這部分,但我似乎看不出問題的原因。 如果可能的話,我將不勝感激::)
閱讀BottomNavigationBar
backgroundColor
的描述,它說
如果 [type] 是 [BottomNavigationBarType.shifting] 並且 [items] 設置了 [BottomNavigationBarItem.backgroundColor],則 [items] 的 backgroundColor 將飛濺並覆蓋此顏色。
因此,解決方案可以是將backgroundColor
設置為您的BottomNavigationItem
之一,它將應用於整個BottomNavigationBar
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.