简体   繁体   中英

How can I get the height of Android bottom software Navigation Bar in Xamarin.Form app?

I'm confused that in different documents, Navigation Bar refers to different controls, but here, it is the Android feature, which provides navigation controls besides the hardware buttons. I hope to get the height of this bar wide code.

After digging solutions about hiding the bar permanently, I reaized it's not possible to do so (which is the most desiered way of sovling the problem), please do correct me if the bar can be hide permanently!!! I attached the code here I used to hide the bar, but whenever I tap the screen, the bar re-appear.

Instead, can I get the height of the bottom software navigation bar on Android so that I can adjust the position of page elements accordingly? (What is more annyoing is that some Android devices allow user the manually show and hide the bar by clicking an arrow button on the bar.)

//In OnCreate of MainActivity.cs,

int uiOptions = (int)Window.DecorView.SystemUiVisibility;
uiOptions |= (int)SystemUiFlags.HideNavigation;
Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;

//In some topics, people said to add some more SystemUiFlags, such as IMMERSIVE_STICKY, LAYOUT_FULLSCREEN, but with those, the bar cannot be hidden.

在此处输入图片说明 Strangly, DeviceDisplay.MainDisplayInfo.Height includes the height of the Navigation bar, otherwise I don't need to do what described above. Is there a way of detecting screen height without the software navigation bar?

Thanks so much for any help on this.

PS: Instead of getting the height, can I at least detect if the software navigation bar is on / shown?! Now I know I can detect if the device has hard navigation keys with ViewConfiguration.Get(Android.App.Application.Context).HasPermanentMenuKey, this is useful, but I still can't detect if the soft navigation bar is on or not.

About get Navigation bar height in xamarin.form, you can try to use:

 TypedArray styledAttributes = this.Theme.ObtainStyledAttributes(new int[] {Android.Resource.Attribute.ActionBarSize });
        var actionbarHeight = (int)styledAttributes.GetDimension(0, 0);
        styledAttributes.Recycle();
        Console.WriteLine("the height is {0}",actionbarHeight);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM