首页 > 解决方案 > 在 Xamarin.Forms 中的导航上隐藏 BottomNavigationView(仅限 Android)

问题描述

我正在使用新的 Xamarin.Forms 功能使用以下属性为 Android 设置底部的 Tabbar

xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" android:TabbedPage.ToolbarPlacement="Bottom"

导航到其他页面时,我需要隐藏标签栏。我编写了一个从 TabbedPageRenderer 继承的自定义渲染器,但我无法使用 OnElementChanged 获取 BottomNavigationView 的实例。

标签: androidxamarin.formstabbarbottomnavigationview

解决方案


理想情况下,您应该将 TabbedPage 保留在 NavigationPage 中,并将新页面推送到 TabbedPage 之上。

您无法获取 BottomNavigationView 参考,因为它是一个私有字段。虽然,您可以使用反射来设置其值,但我强烈建议您反对。

var info = typeof(TabbedPageRenderer).GetTypeInfo();
var _bottomNavigationView = (BottomNavigationView)info.GetField("_bottomNavigationView", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);`

推荐阅读