Skip to content

NavigationRailLabelType 继承自: Enum

定义 NavigationRail 中目的地标签的显示方式。

该设置影响的是未展开(extended 为 False)时的导航栏布局。当导航栏处于展开状态时,无论该取值如何,标签都会显示在图标旁边。

示例 ​

python
import flet as ft


def showcase_card(label_type: ft.NavigationRailLabelType) -> ft.Container:
    rail = ft.NavigationRail(
        width=100,
        height=220,
        selected_index=1,
        label_type=label_type,
        destinations=[
            ft.NavigationRailDestination(icon=ft.Icons.HOME, label="Home"),
            ft.NavigationRailDestination(icon=ft.Icons.SEARCH, label="Search"),
            ft.NavigationRailDestination(icon=ft.Icons.PERSON, label="Profile"),
        ],
    )

    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,
            horizontal_alignment=ft.CrossAxisAlignment.CENTER,
            controls=[
                ft.Text(label_type.name, weight=ft.FontWeight.BOLD),
                rail,
            ],
        ),
    )


def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    page.appbar = ft.AppBar(title="NavigationRailLabelType Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text("Compare label visibility in compact navigation rail."),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[showcase_card(t) for t in ft.NavigationRailLabelType],
                    ),
                ],
            ),
        )
    )


if __name__ == "__main__":
    ft.run(main)

枚举值 ​

名称类型默认值说明
NONE—'none'Hides labels for all destinations. Only destination icons are shown.
ALL—'all'Shows labels for all destinations.
SELECTED—'selected'Shows the label only for the selected destination. As selection changes, the visible label transitions to the newly selected destination.

关注我,学习大模型、大数据、Python等热门技术。