Android 上的 TabbedPage 工具栏位置

此 .NET Multi-platform App UI (.NET MAUI) Android 平台特定功能用于设置工具栏在 TabbedPage 上的位置。 其使用方式为,在 XAML 中将 TabbedPage.ToolbarPlacement 附加属性设置为 ToolbarPlacement 枚举的值:

<TabbedPage ...
            xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls"
            android:TabbedPage.ToolbarPlacement="Bottom">
    ...
</TabbedPage>

或者,可以使用 Fluent API 从 C# 使用它:

using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
...

On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);

注意

此平台特定功能对基于 Shell 的应用中的选项卡没有影响。

TabbedPage.On<Microsoft.Maui.Controls.PlatformConfiguration.Android> 方法指定这一平台特定功能仅可在 Android 上运行。 Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific 命名空间中的 TabbedPage.SetToolbarPlacement 方法用于在 TabbedPage 上设置工具栏位置,其中 ToolbarPlacement 枚举提供以下值:

  • Default – 指示工具栏在页面上的默认位置。 在手机上,它指的是页面的顶部,而在其他设备上,它指的是页面的底部。
  • Top – 指示工具栏位于页面的顶部。
  • Bottom – 指示工具栏位于页面的底部。

注意

GetToolbarPlacement 方法可用于检索 TabbedPage 工具栏的位置。

结果是可以在 TabbedPage 上设置工具栏位置:

TabbedPage toolbar configuration.