[英]How to change the selected tab background colours in flutter
這是你想要的?
class TabBarExample extends StatefulWidget {
@override
_TabBarExampleState createState() => _TabBarExampleState();
}
class _TabBarExampleState extends State<TabBarExample>
with SingleTickerProviderStateMixin {
// Define a tab controller object
TabController _tabController;
@override
void initState() {
_tabController = TabController(length: 3, vsync: this);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
color: Colors.grey[300],
child: TabBar(
controller: _tabController,
indicatorColor: Colors.transparent,
labelColor: Colors.pink,
unselectedLabelColor: Colors.grey,
labelStyle: TextStyle(
fontSize: 16,
),
unselectedLabelStyle: TextStyle(
fontSize: 16,
),
indicator: BoxDecoration(
color: Colors.white,
),
tabs: <Widget>[
Tab(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('STEP 1'),
Text(
'Investment',
style: TextStyle(
fontSize: 12,
),
),
],
),
),
Tab(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('STEP 2'),
Text(
'Investment',
style: TextStyle(fontSize: 12),
),
],
),
),
Tab(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('STEP 3'),
Text(
'Investment',
style: TextStyle(fontSize: 12),
),
],
),
),
],
),
),
),
);
}
}
OUTPUT:
對於未選擇的標簽顏色:用 ColoredBox 包裹並給出您的顏色。
對於選定的選項卡顏色:給一個 BoxDecoration 以您所需的顏色作為指示器。
ColoredBox(
/// Unselected tab color
color: Colors.black,
child: TabBar(
/// Selected tab color
indicator: BoxDecoration(color: Colors.white),
tabs: const [
Tab(text: 'A'),
Tab(text: 'B'),
],
),
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.