向标题栏添加按钮 Xamarin Forms

Adding a button to the title bar Xamarin Forms

还没有找到完全正确的答案。我想在 Xamarin Forms 导航页面顶部的导航/标题栏中添加一个按钮。请注意,我需要知道一种适用于 android 的方法,我对尝试在此处寻找仅 iOS 的解决方案不感兴趣。这个按钮需要是一个图像按钮,因为我想要一种访问汉堡菜单的方法。

使用 YourPage.xaml.cs 中的 ToolbarItem:

ToolbarItems.Add(new ToolbarItem("Search", "search.png",() =>
{
  //logic code goes here
}));

在Xaml中:

<ContentPage.ToolbarItems> 
    <ToolbarItem Icon="search.png" Text="Search" Clicked="Search_Clicked"/>
</ContentPage.ToolbarItems>

更新

Xamarin.Forms在3.2.0中引入TitleView可以自定义导航的标题。

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TestPage">
    <NavigationPage.TitleView>
        <Button ... />
    </NavigationPage.TitleView>
    ...
</ContentPage>