我不确定这是否可以使用现有的工具栏实现,但我有类似的要求,我不知道如何实现在导航页面上使用Xamarin表单工具栏。因此我决定使用模态页面,并在后面的代码中禁用导航页面,并使用下面的代码行。
NavigationPage.SetHasNavigationBar(this, false);
我使用XAML和我创建了absolutelayout自定义导航如下
<AbsoluteLayout x:Name="slToolbar" Grid.Row="0" >
<Button x:Name="Cancel" BackgroundColor="#ADD8E6" Image="cancel.png" Command="{Binding CancelClick}" AbsoluteLayout.LayoutFlags="PositionProportional">
<AbsoluteLayout.LayoutBounds>
<OnPlatform x:TypeArguments="Rectangle" iOS="0, .5, 36, 36" Android="0, .5, 36, 36" WinPhone="0, .5, 50, 50" />
</AbsoluteLayout.LayoutBounds>
</Button>
<StackLayout Orientation="Horizontal" AbsoluteLayout.LayoutFlags="PositionProportional">
<AbsoluteLayout.LayoutBounds>
<OnPlatform x:TypeArguments="Rectangle" iOS="1,.5,110,50" Android="1,.5,50,36" WinPhone="1,.5,110,50" />
</AbsoluteLayout.LayoutBounds>
<ContentView >
<OnPlatform x:TypeArguments="View">
<OnPlatform.iOS>
<Button x:Name="NewIOS" BackgroundColor="#ADD8E6" Image="ic_add.png" Command="{Binding AddNew}" ></Button>
</OnPlatform.iOS>
<OnPlatform.WinPhone>
<Button x:Name="NewWP" BackgroundColor="#ADD8E6" Command="{Binding AddNew}" Image="ic_add.png"/>
</OnPlatform.WinPhone>
</OnPlatform>
</ContentView>
<Button x:Name="btnSave" BackgroundColor="#ADD8E6" Image="check.png" Command="{Binding SaveClick}" HorizontalOptions="End" ></Button>
</StackLayout>
</AbsoluteLayout>
这个代码将产生类似下面。我有角落里的图标,但它们肯定可以放在任何地方。我用取消图标而不是后退按钮。当然,在这种情况下,你需要处理后退按钮(取消按钮)点击你自己。下面的截图是从UWP应用程序,但在Android和IOS我得到类似的结果。
我认为你的问题为android。它似乎不可能,除非你禁用工具栏并创建你自定义的。我有类似的要求,我最终做自定义工具栏 – batmaci
@ batmaci你可以给我的指示或参考,因为我从来没有做过自定义渲染? –
我不是指自定义渲染器,而是自定义工具栏。我给你作为答案。 – batmaci