關鍵代碼
bottom: PreferredSize( preferredSize: Size.fromHeight(48), child: Material( //這里設置tab的背景色 color: Colors.green, child: TabBar( // indicator: ColorTabIndicator(Colors.black),//選中時標簽顏色 indicatorColor: Colors.black,//選中時下划線顏色,如果使用了indicator這里設置無效 controller: _tabController, labelColor: Colors.white, unselectedLabelColor: Colors.yellow, tabs: _tabs.map((item)=>Tab(text: item,)).toList(), ), ), ) )
tabbar中的tab的背景顏色取的實際是AppBar的主題色,所以我們將tabbar放在Material中來重置了主題色,變成我們想要的背景色.
完整代碼:
import 'package:flutter/material.dart'; class TabbarBgColorTest extends StatefulWidget{