如何自定义TabBar指标宽度和高度?
答
给你TabBar
的isScrollable: true
的属性,如果你不想要的选项卡扩展以填充屏幕水平,他们在默认情况下做的方式。
您可以使用包裹在PreferredSize
中的Container
来确定TabBar
的大小。 (PreferredSize
仅在您希望它位于AppBar
的bottom
插槽中时才有必要)。由于TabBar
未填满屏幕,因此这会导致指示器显示变窄。但是,该指标具有硬编码的高度。如果你不喜欢它,你将不得不导入你自己的tabs.dart的副本,并自定义该文件中的常量。
请注意,您也可以使用Container
来设置单个Tab
的高度,尽管这看起来不像您想要做的。
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new DefaultTabController(
length: 2,
child: new Scaffold(
appBar: new AppBar(
title: new Text('Tabs Demo'),
bottom: new PreferredSize(
preferredSize: new Size(200.0, 200.0),
child: new Container(
width: 200.0,
child: new TabBar(
tabs: [
new Container(
height: 200.0,
child: new Tab(text: 'hello'),
),
new Container(
height: 200.0,
child: new Tab(text: 'world'),
),
],
),
),
),
),
// body: ...
),
);
}
}