Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide Android tabs using Xamarin Forms custom renderer?

In Xamarin Forms, I need to write a custom TabbedPageRenderer to hide the Android tabbar. However, I don't know how to do this.

[assembly: ExportRenderer(typeof(CTabbedPage), typeof(CTabbedPageRenderer))]
namespace App15.Droid
{
    public class CTabbedPageRenderer : TabbedPageRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                (this.Context as Activity).ActionBar.NavigationMode = ActionBarNavigationMode.Standard;
            }
        }
    }
}

This code throws an exception because ActionBar is set to null. I'm using AppCompat 23.3.0 and XF 2.3.2.118-pre1.

EDIT: I'm thinking the reason ActionBar is null is Toolbar has replaced it, but I still don't know how to hide tabs. Also, I'm not interested in pushing pages modally.

I also tried adding android:visibility="gone" to Tabbar.axml. This successfully hides the tabbar but the tabbar still occupies space.

like image 720
Mark13426 Avatar asked Aug 02 '16 17:08

Mark13426


1 Answers

This is a known bug in Xamarin: android:visibility="gone" in Tabbar.axml does not reclaim space (Status: CONFIRMED).

As soon as it's fixed, using above approach seems to be a way to go.

like image 153
serv-inc Avatar answered Oct 06 '22 23:10

serv-inc