• Flutter——最详细(AppBar)使用教程


    AppBar简介

    Material Design 应用栏(标题栏)

    使用场景:

    顶部标题栏包括一些常用的菜单按钮

    属性作用
    leading左边工具视图
    automaticallyImplyLeading左边图标的颜色
    title标题视图
    actions右边菜单按钮
    flexibleSpace其高度将与应用栏的整体高度相同
    bottom左侧底部文本内容
    elevation底部阴影
    scrolledUnderElevation左侧底部文本最大行数
    shadowColor阴影样式
    surfaceTintColor应用栏背景色以指示高度的表面色调叠加的颜色
    shape标题栏样式选择
    backgroundColor标题栏背景色
    foregroundColor标题栏前景色
    iconTheme用于工具栏图标的颜色、不透明度和大小
    actionsIconTheme用于工具栏图标的颜色、不透明度和大小
    primary此应用栏是否显示在屏幕顶部
    centerTitle标题是否居中
    excludeHeaderSemantics标题是否应使用标题 Semantics 包装
    titleSpacing标题间距
    toolbarOpacity应用栏的工具栏部分的不透明程度
    bottomOpacity应用栏底部的不透明程度
    toolbarHeight标题栏高度
    leadingWidth左边视图宽度
    toolbarTextStyle主题相关,所有AppBar的字体样式
    titleTextStyle主题相关,所有title的字体样式
    systemOverlayStyle顶部系统状态栏样式

    leading、title、actions: 组合使用效果图

    在这里插入图片描述

    Scaffold(
          appBar: AppBar(
            title: Text('Flutter App Bar'),
            leading: IconButton(
              icon: Icon(Icons.arrow_back),
              onPressed: () {
                // 处理返回操作
              },
            ),
            actions: [
              IconButton(
                icon: Icon(Icons.search),
                onPressed: () {
                  // 处理搜索操作
                },
              ),
              IconButton(
                icon: Icon(Icons.more_vert),
                onPressed: () {
                  // 处理更多操作
                },
              ),
            ],
          ),
          body: Container(),
        );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    iconTheme: 效果图
    要注意 iconTheme 单独使用时,会应用到所有的Icon样式
    actionsIconTheme 两个属性组合使用时,则会区分Icon 样式

    在这里插入图片描述
    在这里插入图片描述

     Scaffold(
          appBar: AppBar(
            title: Text('Flutter App Bar'),
            leading: IconButton(
              icon: Icon(Icons.arrow_back),
              onPressed: () {
                // 处理返回操作
              },
            ),
            iconTheme: IconThemeData(
              color: Colors.red, // 修改图标颜色
              size: 30.0,       // 修改图标大小
            ),
            actionsIconTheme: IconThemeData(
              color: Colors.blue, // 修改图标颜色
              size: 30.0, // 修改图标大小
            ),
            actions: [
              IconButton(
                icon: Icon(Icons.search),
                onPressed: () {
                  // 处理搜索操作
                },
              ),
              IconButton(
                icon: Icon(Icons.more_vert),
                onPressed: () {
                  // 处理更多操作
                },
              ),
            ],
          ),
          body: Container(),
        );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    backgroundColor: 背景色 黄色
    foregroundColor: 前景色 绿色 会覆盖标题的色值

    在这里插入图片描述

    Scaffold(
          appBar: AppBar(
            title: Text('我是绿色'),
            leading: IconButton(
              icon: Icon(Icons.arrow_back),
              onPressed: () {
                // 处理返回操作
              },
            ),
            iconTheme: IconThemeData(
              color: Colors.red, // 修改图标颜色
              size: 30.0, // 修改图标大小
            ),
            actionsIconTheme: IconThemeData(
              color: Colors.blue, // 修改图标颜色
              size: 30.0, // 修改图标大小
            ),
            backgroundColor: Colors.yellow,
            foregroundColor: Colors.greenAccent,
            actions: [
              IconButton(
                icon: Icon(Icons.search),
                onPressed: () {
                  // 处理搜索操作
                },
              ),
              IconButton(
                icon: Icon(Icons.more_vert),
                onPressed: () {
                  // 处理更多操作
                },
              ),
            ],
          ),
          body: Container(),
        );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    titleTextStyle: 标题字体样式
    titleSpacing: 标题左边间距

    在这里插入图片描述

    Scaffold(
          appBar: AppBar(
            title: Text('我是紫色'),
            leading: IconButton(
              icon: Icon(Icons.arrow_back),
              onPressed: () {
                // 处理返回操作
              },
            ),
            iconTheme: IconThemeData(
              color: Colors.red, // 修改图标颜色
              size: 30.0, // 修改图标大小
            ),
            actionsIconTheme: IconThemeData(
              color: Colors.blue, // 修改图标颜色
              size: 30.0, // 修改图标大小
            ),
            backgroundColor: Colors.yellow,
            foregroundColor: Colors.greenAccent,
            titleTextStyle: TextStyle(
              color: Colors.deepPurple,   // 修改标题文本颜色
              fontSize: 24.0,       // 修改标题文本字体大小
              fontWeight: FontWeight.bold,  // 修改标题文本字体粗细
            ),
            titleSpacing: 30,
            actions: [
              IconButton(
                icon: Icon(Icons.search),
                onPressed: () {
                  // 处理搜索操作
                },
              ),
              IconButton(
                icon: Icon(Icons.more_vert),
                onPressed: () {
                  // 处理更多操作
                },
              ),
            ],
          ),
          body: Container(),
        );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    centerTitle: 标题是否居中展示,默认靠左
    toolbarHeight: 标题栏的高度

    在这里插入图片描述

    Scaffold(
          appBar: AppBar(
            title: Text(' App Bar'),
            leading: IconButton(
              icon: Icon(Icons.arrow_back),
              onPressed: () {
                // 处理返回操作
              },
            ),
            iconTheme: IconThemeData(
              color: Colors.red, // 修改图标颜色
              size: 30.0, // 修改图标大小
            ),
            actionsIconTheme: IconThemeData(
              color: Colors.blue, // 修改图标颜色
              size: 30.0, // 修改图标大小
            ),
            backgroundColor: Colors.yellow,
            foregroundColor: Colors.greenAccent,
            centerTitle: true,
            titleTextStyle: TextStyle(
              color: Colors.deepPurple, // 修改标题文本颜色
              fontSize: 24.0, // 修改标题文本字体大小
              fontWeight: FontWeight.bold, // 修改标题文本字体粗细
            ),
            toolbarHeight: 100,
            actions: [
              IconButton(
                icon: Icon(Icons.search),
                onPressed: () {
                  // 处理搜索操作
                },
              ),
              IconButton(
                icon: Icon(Icons.more_vert),
                onPressed: () {
                  // 处理更多操作
                },
              ),
            ],
          ),
          body: Container(),
        );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    systemOverlayStyle: 系统状态栏样式修改

    在这里插入图片描述

    Scaffold(
          appBar: AppBar(
            title: Text(' App Bar'),
            leading: IconButton(
              icon: Icon(Icons.arrow_back),
              onPressed: () {
                // 处理返回操作
              },
            ),
            iconTheme: IconThemeData(
              color: Colors.red, // 修改图标颜色
              size: 30.0, // 修改图标大小
            ),
            actionsIconTheme: IconThemeData(
              color: Colors.blue, // 修改图标颜色
              size: 30.0, // 修改图标大小
            ),
            backgroundColor: Colors.yellow,
            foregroundColor: Colors.greenAccent,
            centerTitle: true,
            titleTextStyle: TextStyle(
              color: Colors.deepPurple, // 修改标题文本颜色
              fontSize: 24.0, // 修改标题文本字体大小
              fontWeight: FontWeight.bold, // 修改标题文本字体粗细
            ),
            toolbarHeight: 100,
            actions: [
              IconButton(
                icon: Icon(Icons.search),
                onPressed: () {
                  // 处理搜索操作
                },
              ),
              IconButton(
                icon: Icon(Icons.more_vert),
                onPressed: () {
                  // 处理更多操作
                },
              ),
            ],
            systemOverlayStyle: SystemUiOverlayStyle(
              statusBarColor: Colors.blue, // 设置状态栏背景颜色
              statusBarIconBrightness: Brightness.dark, // 设置状态栏图标的亮度,dark表示黑色图标
            ),
          ),
          body: Container(),
        );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    toolbarOpacity: 设置标题栏透明度 0.5

    在这里插入图片描述

      toolbarOpacity: 0.5,
    
    • 1
  • 相关阅读:
    vision transformer的计算复杂度
    2023-09-05力扣每日一题
    头歌计算机组成原理MIPS寄存器文件设计
    SQL基础查询与排序
    vue,Promise备忘
    Linux扩展篇之Shell编程一(Shell 概述)
    如何使用Git和GitHub进行版本控制
    ElasticSearch源码解析(二):ES的CharFilter、Tokenizer、TokenizerFilter
    PHP数组转json和php的json转数组
    【PyTorch实战演练】深入剖析MTCNN(多任务级联卷积神经网络)并使用30行代码实现人脸识别
  • 原文地址:https://blog.csdn.net/u013290250/article/details/134296716