主题
NavigationBarLabelBehavior 继承自: Enum
Defines how the destinations' labels will be laid out and when they'll be displayed.
示例
python
import flet as ft
def showcase_card(behavior: ft.NavigationBarLabelBehavior) -> ft.Container:
bar = ft.NavigationBar(
label_behavior=behavior,
selected_index=1,
destinations=[
ft.NavigationBarDestination(icon=ft.Icons.HOME, label="Home"),
ft.NavigationBarDestination(icon=ft.Icons.SEARCH, label="Search"),
ft.NavigationBarDestination(icon=ft.Icons.PERSON, label="Profile"),
],
)
return ft.Container(
width=380,
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(behavior.name, weight=ft.FontWeight.BOLD),
bar,
],
),
)
def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.appbar = ft.AppBar(title="NavigationBarLabelBehavior Showcase")
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Text("Compare destination label visibility strategies."),
ft.Row(
wrap=True,
spacing=12,
expand=True,
scroll=ft.ScrollMode.AUTO,
alignment=ft.MainAxisAlignment.CENTER,
controls=[
showcase_card(behavior)
for behavior in ft.NavigationBarLabelBehavior
],
),
],
),
)
)
if __name__ == "__main__":
ft.run(main)枚举值
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
ALWAYS_SHOW | — | 'alwaysShow' | Always shows the label below every destination, selected and unselected. |
ALWAYS_HIDE | — | 'alwaysHide' | Hides every destination label, regardless of which destination is selected. |
ONLY_SHOW_SELECTED | — | 'onlyShowSelected' | Shows the label only for the selected destination. Unselected destinations hide their labels and keep the icon centered. When a destination becomes selected, its label fades in and the label/icon pair shifts so both remain centered together. |