主题
FloatingActionButtonLocation 继承自: Enum
Defines a position for the FloatingActionButton.
示例
python
import flet as ft
def showcase_card(location: ft.FloatingActionButtonLocation) -> ft.Container:
mini = location.name.startswith("MINI_")
return ft.Container(
width=300,
padding=12,
border=ft.Border.all(1, ft.Colors.RED),
border_radius=10,
bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
content=ft.Column(
spacing=8,
controls=[
ft.Text(location.name, weight=ft.FontWeight.BOLD),
ft.Pagelet(
width=260,
height=200,
bgcolor=ft.Colors.SURFACE,
appbar=ft.AppBar(
title=ft.Text("AppBar", size=12),
center_title=True,
toolbar_height=38,
bgcolor=ft.Colors.PRIMARY_CONTAINER,
),
content=ft.Container(
alignment=ft.Alignment.CENTER,
content=ft.Text("Body", size=12),
),
bottom_appbar=ft.BottomAppBar(
height=42,
bgcolor=ft.Colors.SECONDARY_CONTAINER,
),
floating_action_button=ft.FloatingActionButton(
icon=ft.Icons.ADD,
mini=mini,
bgcolor=ft.Colors.LIGHT_BLUE_400,
),
floating_action_button_location=location,
),
],
),
)
def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.appbar = ft.AppBar(title="FloatingActionButtonLocation Showcase")
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Text("Compare FloatingActionButton placement presets."),
ft.Row(
wrap=True,
spacing=12,
expand=True,
scroll=ft.ScrollMode.AUTO,
alignment=ft.MainAxisAlignment.CENTER,
controls=[
showcase_card(location)
for location in ft.FloatingActionButtonLocation
],
),
],
),
)
)
if __name__ == "__main__":
ft.run(main)枚举值
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
CENTER_DOCKED | — | 'centerDocked' | Centered FloatingActionButton, floating over a bottom navigation control so the button's center lines up with the top of that control. Not typically useful for apps without a bottom navigation control. |
CENTER_FLOAT | — | 'centerFloat' | Centered FloatingActionButton, floating at the bottom of the screen. Use MINI_CENTER_FLOAT for mini buttons. |
CENTER_TOP | — | 'centerTop' | Centered FloatingActionButton, floating over the transition between the AppBar and the page body. Not typically useful for apps without a top AppBar. |
END_CONTAINED | — | 'endContained' | End-aligned FloatingActionButton, floating over a bottom navigation control so the button lines up with that control's center. Not typically useful for apps with a NavigationBar or a non-Material 3 BottomAppBar. |
END_DOCKED | — | 'endDocked' | End-aligned FloatingActionButton, floating over a bottom navigation control so the button's center lines up with the top of that control. Not typically useful for apps without a bottom navigation control. |
END_FLOAT | — | 'endFloat' | End-aligned FloatingActionButton, floating at the bottom of the screen. This is the default alignment in Material apps. Use MINI_END_FLOAT for mini buttons. |
END_TOP | — | 'endTop' | End-aligned FloatingActionButton, floating over the transition between the AppBar and the page body. Not typically useful for apps without a top AppBar. |
MINI_CENTER_DOCKED | — | 'miniCenterDocked' | Centered mini FloatingActionButton, floating over a bottom navigation control so the button's center lines up with the top of that control. Intended for use with mini buttons. |
MINI_CENTER_FLOAT | — | 'miniCenterFloat' | Centered mini FloatingActionButton, floating at the bottom of the screen. Intended for use with mini buttons. |
MINI_CENTER_TOP | — | 'miniCenterTop' | Centered mini FloatingActionButton, floating over the transition between the AppBar and the page body. Intended for use with mini buttons. |
MINI_END_DOCKED | — | 'miniEndDocked' | End-aligned mini FloatingActionButton, floating over a bottom navigation control so the button's center lines up with the top of that control. Intended for use with mini buttons. |
MINI_END_FLOAT | — | 'miniEndFloat' | End-aligned mini FloatingActionButton, floating at the bottom of the screen. Intended for use with mini buttons. |
MINI_END_TOP | — | 'miniEndTop' | End-aligned mini FloatingActionButton, floating over the transition between the AppBar and the page body. Intended for use with mini buttons. |
MINI_START_DOCKED | — | 'miniStartDocked' | Start-aligned mini FloatingActionButton, floating over a bottom navigation control so the button's center lines up with the top of that control. Intended for use with mini buttons. |
MINI_START_FLOAT | — | 'miniStartFloat' | Start-aligned mini FloatingActionButton, floating at the bottom of the screen. Intended for use with mini buttons. |
MINI_START_TOP | — | 'miniStartTop' | Start-aligned mini FloatingActionButton, floating over the transition between the AppBar and the page body. Intended for use with mini buttons. |
START_DOCKED | — | 'startDocked' | Start-aligned FloatingActionButton, floating over a bottom navigation control so the button's center lines up with the top of that control. Not typically useful for apps without a bottom navigation control. |
START_FLOAT | — | 'startFloat' | Start-aligned FloatingActionButton, floating at the bottom of the screen. Use MINI_START_FLOAT for mini buttons. |
START_TOP | — | 'startTop' | Start-aligned FloatingActionButton, floating over the transition between the AppBar and the page body. Not typically useful for apps without a top AppBar. |