Flutter 顶部导航标签组件Tab + TabBar + TabController

Tab定义标题

TabBarView定义内容区域

TabController 控制切换

TabBar

属性 说明
isScrollable tab是否可滑动
indicatorColor 指示器的颜色
indicatorWeight 指示器的高度
labelColor 选中tab的颜色
unselectedLabelColor 选中tab的颜色
dart 复制代码
class MyState extends State {
  @override
  Widget build(BuildContext context) {
    TabBar tabBar = TabBar(
      unselectedLabelColor: Colors.cyan,
      labelColor: Colors.green ,
      indicatorColor: Colors.blue,
      indicatorWeight: 10,
      isScrollable: true,
      tabs: [
        Tab(icon: Icon(Icons.account_circle), text: "首页"),
        Tab(icon: Icon(Icons.account_circle), text: "视频"),
        Tab(icon: Icon(Icons.account_circle), text: "消息"),
        Tab(icon: Icon(Icons.account_circle), text: "购物"),
        Tab(icon: Icon(Icons.account_circle), text: "我的"),
      ],
    );

    TabBarView tabBarView = TabBarView(
      children: [
        Center(child: Text("首页")),
        Center(child: Text("视频")),
        Center(child: Text("消息")),
        Center(child: Text("购物")),
        Center(child: Text("我的")),
      ],
    );

    return DefaultTabController(
      length: 5,
      child: Scaffold(
        appBar: AppBar(title: Text("购物"), bottom: tabBar),
        body: tabBarView,
      ),
    );
  }
}
相关推荐
fatiaozhang95274 小时前
中兴B860AV5.2-U_原机安卓4.4.2系统专用_晶晨S905L3SB处理器_线刷固件包
android·电视盒子·刷机固件·机顶盒刷机·中兴b860av5.2-u
子榆.4 小时前
Flutter 与开源鸿蒙(OpenHarmony)深度集成实战:从零构建跨平台应用
flutter·开源·harmonyos
儿歌八万首4 小时前
Android 自定义 View 实战:打造一个跟随滑动的丝滑指示器
android·kotlin
我有与与症4 小时前
Kuikly 实战:手把手撸一个跨平台 AI 聊天助手 (ChatDemo)
android
恋猫de小郭4 小时前
Flutter UI 设计库解耦重构进度,官方解答未来如何适配
android·前端·flutter
apihz4 小时前
全球IP归属地查询免费API详细指南
android·服务器·网络·网络协议·tcp/ip
hgz07105 小时前
Linux环境下MySQL 5.7安装与配置完全指南
android·adb
Just_Paranoid5 小时前
【Android UI】Android 添加圆角背景和点击效果
android·ui·shape·button·textview·ripple
梁同学与Android5 小时前
Android ---【经验篇】阿里云 CentOS 服务器环境搭建 + SpringBoot项目部署(二)
android·spring boot·后端