AppBar
一个 Material Design 的应用栏。
示例
AppBar
- Python
import flet as ft
def main(page: ft.Page):
def check_item_clicked(e):
e.control.checked = not e.control.checked
page.update()
page.appbar = ft.AppBar(
leading=ft.Icon(ft.Icons.PALETTE),
leading_width=40,
title=ft.Text("AppBar Example"),
center_title=False,
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGHEST,
actions=[
ft.IconButton(ft.Icons.WB_SUNNY_OUTLINED),
ft.IconButton(ft.Icons.FILTER_3),
ft.PopupMenuButton(
items=[
ft.PopupMenuItem(text="Item 1"),
ft.PopupMenuItem(), # divider
ft.PopupMenuItem(
text="Checked item", checked=False, on_click=check_item_clicked
),
]
),
],
)
page.add(ft.Text("Body!"))
ft.app(target=main)

属性
actions
在标题控件后显示在一行中的Control
列表。
通常这些控件是代表常见操作的IconButtons
。对于不太常见的操作,考虑使用PopupMenuButton
作为最后一个动作。
注意,如果AppBar.adaptive=True
且应用在iOS或macOS设备上打开,则只会使用此列表中的第一个元素。这是因为在这些平台上使用的CupertinoAppBar
仅接受一个尾随动作控件。
adaptive
如果值为True
,则会根据目标平台是iOS/macOS来创建自适应的AppBar。
在iOS和macOS上,会创建一个CupertinoAppBar
,它具有与AppBar
匹配的功能和外观,并且符合iOS的图形效果。在其他平台上,会创建一个Material AppBar。
bool
型,默认值为False
。
automatically_imply_leading
控制是否在leading
为空时尝试推断leading
控件。
如果为True
且leading
为空,会自动尝试推断leading
控件。如果为False
且leading
为空,标题会占用leading
空间。如果leading
控件不为空,此参数无效。
bgcolor
用于AppBar的填充颜色。默认颜色由当前主题定义。
center_title
标题是否居中。默认值为False
。
clip_behavior
根据此选项裁剪(或不裁剪)内容。属性值为ClipBehavior
。
color
AppBar中Text
和Icon
控件的默认颜色。默认颜色由当前主题定义。
elevation
AppBar的高度。默认值为4
。
注意:当使用Material 2设计时(当Theme.use_material3=False
),此效果才可见。
值的类型为 OptionalNumber
,默认值为 4
。
elevation_on_scroll
如果有内容在AppBar下滚动时使用的高度。
值的类型为 OptionalNumber
exclude_header_semantics
标题是否应包装在标题Semantics
中。默认值为False
。
force_material_transparency
强制使AppBar透明(而不是Material的默认类型)。
这也会移除bgcolor
和elevation