一、Flutter AppBar 自定义顶部按钮图标、颜色
leading   在标题前面显示的一个控件,在首页通常显示应用的 logo;在其他界面通常显示为返回按钮
title  标题,通常显示为当前界面的标题文字,可以放组件
actions  通常使用 IconButton 来表示,可以放按钮组
bottom  通常放 tabBar,标题下面显示一个 Tab 导航栏
backgroundColor  导航背景颜色
iconTheme  图标样式
textTheme  文字样式
centerTitle  标题是否居中显示
 
 
 
二、Flutter AppBar 中自定义 TabBar 实现顶部 Tab 切换
tabs  显示的标签内容,一般使用 Tab 对象,也可以是其他的 Widget
controller TabController 对象
isScrollable  是否可滚动
indicatorColor  指示器颜色
indicatorWeight 指示器高度
indicatorPadding  底部指示器的 Padding
indicator  指示器 decoration,例如边框等
indicatorSize  指示器大小计算方式,TabBarIndicatorSize.label 跟文字等宽,TabBarIndicatorSize.tab 跟每个 tab 等宽
labelColor  选中 label 颜色
labelStyle 选中 label 的 Style
labelPadding  每个 label 的 padding 值
unselectedLabelColor  未选中 label 颜色
unselectedLabelStyle   未选中 label 的 Style
 
案例代码
import 'package:flutter/material.dart';

class ClassIf extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Row( // 或者buttom
children: <Widget>[
Expanded(
flex: 1,
child: TabBar(
tabs: <Widget>[
Tab(text: '分类一'),
Tab(text: '分类二')
],
),
)
],
),
),
body: TabBarView(
children: <Widget>[
ListView(
children: <Widget>[
Text('132'),
Text('132'),
Text('132'),
],
),
ListView(
children: <Widget>[
Text('132'),
Text('132'),
Text('132'),
],
)
],
),
),
);
}
}
三、Flutter AppBar 中自定义 TabBar 实现 Tabs 的另一种方法 带数据,带下拉更多的时候
   通过TabController 定义TabBar
      页面必须继承StatefulWidget
     页面必须实现SingleTickerProviderStateMixin

     页面初始化时,实例化TabController
     在TabBar组件中指定controller为我们实例化的TabController
     在TabBarView组件中指定controller为我们实例化的TabController

 主要是监听TabBar与TabBarView的交互。比如,我们可以在tab切换时加载不同数据;可以自定义切换动画等。

参数详解
  animation 官方:一个动画,其值表示TabBar所选选项卡指示器的当前位置以及TabBar 和TabBarView的scrollOffsets。
  index 当前tab索引,//跳转后执行
  indexIsChanging 动画是时为true
  length tab总数
  offset 动画的值和索引之间的差异。偏移量必须在-1.0和1.0之间
  previousIndex 前tab索引,////跳转后执行

方法详解 
  animateTo 从当前tab跳到目标tab并执行动画
  dispose 销毁
  addListener 添加监听
  noSuchMethod 当访问不存在的属性或方法时调用(不知道是什么鬼)
  notifyListeners 调用所有监听器
  removeListener 清除监听器

import 'package:flutter/material.dart';
class AppBardemoPage extends StatefulWidget {
AppBardemoPage({Key key}) : super(key: key); _AppBardemoPageState createState() => _AppBardemoPageState();
} class _AppBardemoPageState extends State<AppBardemoPage> with SingleTickerProviderStateMixin {
TabController _tabController; @override void dispose() {
_tabController.dispose();
super.dispose();
} void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this, initialIndex: 0);
_tabController.addListener(() {
print(_tabController.index);
});
  }

  @override Widget build(BuildContext context) {
return new Scaffold(appBar: new AppBar(
title: new Text('顶部 tab 切换'),
bottom: new TabBar(tabs: <Widget>[
new Tab(icon: new Icon(Icons.directions_bike),),
new Tab(icon: new Icon(Icons.directions_boat),),
new Tab(icon: new Icon(Icons.directions_bus),),
], controller: _tabController,),),
body: new TabBarView(controller: _tabController,
children: <Widget>[
new Center(child: new Text('自行车')),
new Center(child: new Text('船')),
new Center(child: new Text('巴士')),
],),);
}
}

自定义tabBar 不放在appBar里面

class TransactionRecord extends StatefulWidget{
createState() => _TransactionRecord();
} class _TransactionRecord extends State with SingleTickerProviderStateMixin{
var _tabController;
@override
initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this, initialIndex: 0);
_tabController.addListener(() {
print(_tabController.index);
});
}
dispose() {
super.dispose();
_tabController.dispose();
}
Widget build(BuildContext context) {
Screen.init(context);
// TODO: implement build
return DefaultTabController(
length: 3,
child: Scaffold(
body: Container(
alignment: Alignment.centerLeft,
color: ColorGather.colorBg(),
child: Column(
children: <Widget>[
Container(
height: 50, color: Colors.white,
child: TabBar(
labelPadding: EdgeInsets.all(0),
controller: _tabController,
tabs: <Widget>[
Tab(child: Text('时间筛选', style: TextStyle(fontSize: Screen.width(28)))),
Tab(child: Text('时间筛选', style: TextStyle(fontSize: Screen.width(28)))),
Tab(child: Text('时间筛选', style: TextStyle(fontSize: Screen.width(28)))),
],
onTap: (val) {},
),
),
Expanded(
child: TabBarView(
controller: _tabController,
children: <Widget>[
Text('123'),
Text('123'),
Text('123'),
],
),
)
],
)
)
),
);
}
}

AppBar 自定义顶部导航按钮 图标、颜色 以及 TabBar 定义顶部 Tab 切换的更多相关文章

  1. Flutter AppBar 自定义顶部导航按钮 图标、颜色 以及 TabBar 定义顶部 Tab 切换

    Flutter AppBar 自定义顶部按钮图 标.颜色 属性 描述 leading 在标题前面显示的一个控件,在首页通常显示应用 的 logo;在其他界面通常显示为返回按钮 title 标题,通常显 ...

  2. 富文本编辑器UEditor自定义工具栏(三、自定义工具栏功能按钮图标及工具栏样式简单修改)

    导读 富文本编辑器UEditor提供丰富了定制配置项,如果想设置个性化的工具栏按钮图标有无办法呢?答案是肯定的!前两篇博文简要介绍了通过将原工具栏隐藏,在自定义的外部按钮上,调用UEditor各命令实 ...

  3. jQuery 顶部导航尾随滚动,固定浮动在顶部

    jQuery 顶部导航尾随滚动.固定浮动在顶部 演示 XML/HTML Code <section> <article class="left"> < ...

  4. 19 Flutter 自定义AppBar 定义顶部Tab切换 底部Tab结合顶部Tab实现类似头条页面布局(27分36秒)

    Flutter AppBar自定义顶部导航按钮图标.颜色以及TabBar定义顶部Tab切换. leading:在标题前面显示的一个控件,在首页通常显示应用的logo:在其他界面通常显示为付汇按钮. t ...

  5. 15 Flutter BottomNavigationBar自定义底部导航条 以及实现页面切换 以及模块化

    效果: /**  * Flutter  BottomNavigationBar 自定义底部导航条.以及实现页面切换:  * BottomNavigationBar是底部导航条,可以让我们定义底部Tab ...

  6. BottomNavigationBar 自定义 底部导航条

    在flutter中,BottomNavigationBar 是底部导航条,可以让我们定义底部 Tab 切换,bottomNavigationBar是 Scaffold 组件的参数. BottomNav ...

  7. tab 切换 和 BottomNavigationBar 自定义 底部导航条

    BottomNavigationBar 组件    BottomNavigationBar 是底部导航条,可以让我们定义底部 Tab 切换,bottomNavigationBar是 Scaffold ...

  8. uni-app自定义导航栏按钮|uniapp仿微信顶部导航条

    最近一直在学习uni-app开发,由于uniapp是基于vue.js技术开发的,只要你熟悉vue,基本上很快就能上手了. 在开发中发现uni-app原生导航栏也能实现一些顶部自定义按钮+搜索框,只需在 ...

  9. 自定义iOS7导航栏背景,标题和返回按钮文字颜色

    在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...

随机推荐

  1. WebViewJavascriptBridge(H5与原生交互)

    https://github.com/wangjiaojiao77/WebViewJavascriptBridge(IOS)和 https://github.com/wangjiaojiao77/Js ...

  2. MyBatis使用步骤及原理

    主要讲解MyBatis-基本使用步骤      回顾:     MyBatis是一个数据持久层(ORM)框架.把实体 类和SQL语句之间建立了映射关系,是一种半自 动化的ORM实现.MyBATIS需要 ...

  3. 题解 P4289 【[HAOI2008]移动玩具】

    题目地址:https://www.luogu.com.cn/problem/P4289 题解原地址:https://createsj.blog.luogu.org/solution-p4289 让我们 ...

  4. 【转载】Hibernate映射文件详解

    转自:http://blog.163.com/hzd_love/blog/static/13199988120108265317988/ Hibernate的持久化类和关系数据库之间的映射通常是用一个 ...

  5. 【算法学习记录-排序题】【PAT A1012】The Best Rank

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  6. count(*)、count(1)、count(column)的区别

    count(*)对行的数目进行计算,包含NULL count(column)对特定的列的值具有的行数进行计算,不包含NULL值. count()还有一种使用方式,count(1)这个用法和count( ...

  7. scrapy 框架基本使用

    scrapy简介: Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取 (更确切来说, 网络抓取 ...

  8. STA之RC Corner再论

    Q:RC-Corner跟PVT怎么组合? A:通常的组合:   Q:通常说的ttcorner指的是啥? A:@孟时光 ttcorner是指管子在tt+RCtyp吧. Typesof corners W ...

  9. layer.open 回调函数

    官方资料:http://www.layui.com/doc/modules/layer.html 在一个弹出框中新增个按钮,点击按钮后执行自己的语句(返回上一页并刷新). layer.open({ti ...

  10. python正则分组

    python的正则表达式本身每一个字符串都是独立的 看下面的例子就理解分组的含义了~ ab*表示的是查找a和(0个或多个b),就是*是单独针对b的,所以返回a (ab)*则表示ab是一个组是一个整体, ...