Forum Xamarin.Forms

How to get NavigationBar height?

I want to get NavigationBar height because i want to place center of the app.
If i get NavigationBar height then i can use margin to place center but i did not find way to get NavigationBar height.

Best Answer


  • FaizalSaidaliFaizalSaidali USMember ✭✭✭

    Hi @PrashantWalia, I think this link will help you for android screen sizes.
    And for iOS click here.

    And also you can identify the screen size of android using this code

    App.ScreenHeight = (int) (Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density);
    App.ScreenWidth = (int) (Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density);

    And the iOS part you can use

    App.ScreenHeight = (int)UIScreen.MainScreen.Bounds.Height;
    App.ScreenWidth = (int)UIScreen.MainScreen.Bounds.Width;
  • PrashantWaliaPrashantWalia USMember ✭✭
    @FaizalSaidali This gives me screen height and width but i suppose to get NavigationBar height.

    Thanks for reply.
  • PrashantWaliaPrashantWalia USMember ✭✭

    @LandLu Thanks its working :)

  • trisimtrisim Member

    @LandLu said:
    @PrashantWalia You can get it on each platform using custom renderer.
    For iOS:

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

    For Android:

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

    Hi @LandLu this might be a stupid question, but how can I access those variables from elsewhere, for example a ViewModel?


  • Jake_PorterJake_Porter USMember ✭✭

    Do you have a full example that includes UWP also?

Sign In or Register to comment.