android - 如何在 Android 上的 Xamarin.Forms 中的 NavigationBar 左侧添加 ToolbarItem?

标签 android xamarin.forms navigationbar custom-renderer

我需要在导航栏左侧关闭按钮(在本例中) , 如下。我只需要它用于弹出窗口,因此其他元素/导航没有潜在问题。

enter image description here

谷歌对此有一些建议,但我只看到了 iOS 示例(这在 iOS 自定义渲染器 中处理起来不是什么大事),但没有提示如何处理它( 轻松)与 Android

为了清楚起见,Xamarin.Forms 需要它来定义类似于此(或代码隐藏)的内容:

<ContentPage.ToolbarItems>
    <ToolbarItem Text="X" Priority="-1" Command="{Binding GoCancel}"/>
    <ToolbarItem Icon="icon_save" Command="{Binding GoSave}"/>
</ContentPage.ToolbarItems>

有什么想法吗?

最佳答案

在 Xamarin Forms 3.2 中,有一种使用 NavigationBar 处理更复杂场景的新方法。它称为 TitleView

有了这个,你可以将你想要的任何 View 推送到 NavigationBar

示例 XAML:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="NavigationPageTitleView.TitleViewPage">
    <NavigationPage.TitleView>
        <Slider HeightRequest="44" WidthRequest="300" />
    </NavigationPage.TitleView>
    ...
</ContentPage>

更多信息请点击此处 https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical#displaying-views-in-the-navigation-bar和示例项目可以在这里找到 https://developer.xamarin.com/samples/xamarin-forms/Navigation/TitleView/

关于android - 如何在 Android 上的 Xamarin.Forms 中的 NavigationBar 左侧添加 ToolbarItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52617416/

相关文章:

xamarin.forms - Xamarin Forms TabbedPage 标题的中心文本

xaml - 如何在 Xamarin Forms 中扩展一个内容 View 而另一个内容 View 具有固定高度

javascript - Jquery .slideToggle() 在导航栏上不起作用?

android - picasso 在使用 View 持有者模式时加载到错误的 ImageView 中

android - 如何使用改造 2 发送帖子对象

android - 我们如何在android中使用带有图像的自定义进度条

c# - 我可以隐藏 Xamarin.Auth NavigationBar 吗?

html - html格式问题中的导航栏

html - 无法在标题图片下对齐导航栏

Android手持设备和可穿戴设备之间的双向通信