How to hide the bottom TabbedPage tabs in .NET MAUI 8?
Satya
155
Reputation points
Actually I need to hide bottom tabs based on some condition.
I tried using TabbedViewHandler and Reflection to hide the tabs by setting height of bototmbar LayoutParameters to 0. Tabs are not visible, but blank space is showing up in space of tabs. I also tried the setting the visibility of bottomBar to Gone, but still white space is showing up. Any help would be highly appreciated.
public static PropertyMapper<BaseBottomBarTabbedPage, CustomTabbedPageHandler> BottomBarMapper = new(Mapper)
{
[nameof(BaseBottomBarTabbedPage.IsBottomBarVisible)] = IsBottomBarVisibleOrNot
};
private static void IsBottomBarVisibleOrNot(CustomTabbedPageHandler handler, BottomBarTabbedPage baseBottomBarTabbedPage)
{
try
{
if (handler != null && handler.PlatformView != null && baseBottomBarTabbedPage != null)
{
var context = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.ApplicationContext;
var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
Type tabbedPageType = typeof(Microsoft.Maui.Controls.TabbedPage);
var tabManager = tabbedPageType.GetField("_tabbedPageManager", flags)?.GetValue(baseBottomBarTabbedPage);
var bottomNavigation = tabManager.GetType().GetField("_bottomNavigationView", flags)?.GetValue(tabManager);
if (bottomNavigation is Google.Android.Material.BottomNavigation.BottomNavigationView bottomBar)
{
var parameters = bottomBar.LayoutParameters;
int resourceId = context.Resources.GetIdentifier("design_bottom_navigation_height", "dimen", context.PackageName);
if (resourceId > 0)
{
bottomBarHeight = context.Resources.GetDimensionPixelSize(resourceId);
}
if (parameters != null)
{
parameters.Height = baseBottomBarTabbedPage.IsBottomBarVisible ? bottomBarHeight : 0;
bottomBar.LayoutParameters = parameters;
}
}
}
}
catch (Exception ex)
{
Crashes.TrackError(ex);
}
}
Sign in to answer