What is default height of navigation bar ?

MigokMigok Member ✭✭
edited December 2018 in Xamarin.Forms

Hello,

I was wondering what is the default height of navigation bar ? Something like 15% of the screen ?
I would like to manually reproduce a navigation bar on a modal page, with the same size than the default navigation bar.

Thanks.

Answers

  • JuniorJiangJuniorJiang Member, Xamarin Team Xamurai

    Hi, in ios, the default height of navigation bar is 44 pts.
    In android, maybe now there is no description in the forms, but you can refer to the Android Title bar to set.It seems that there are two versions of this height, 48dp and 56dp.

    Or,firstly you can use custom renderer to get each of them.Then do something in custom renderer later.
    IOS:

    public class NaviRendererForiOS : NavigationRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
    
            var height = NavigationBar.Bounds.Height;
        }
    }
    

    Android:

    public class NaviRendererForAndroid : NavigationPageRenderer
    {
        public CustomNaviForAndroid(Context context) : base(context)
        {
    
        }
        protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
        {
            base.OnElementChanged(e);
    
            var height = 0;
    
            Resources resources = Context.Resources;
            int resourceId = resources.GetIdentifier("navigation_bar_height", "dimen", "android");
            if (resourceId > 0)
            {
                height = resources.GetDimensionPixelSize(resourceId);
            }
        }
    }
    
Sign In or Register to comment.