繁体   English   中英

如何在Xamarin.Form应用中获取Android底层软件Navigation Bar的高度?

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

我很困惑,在不同的文档中,导航栏指的是不同的控件,但是在这里,它是Android功能,除了硬件按钮之外,它还提供了导航控件。 我希望了解此条形码的高度。

在找到有关永久隐藏栏的解决方案之后,我发现不可能这样做(这是解决问题的最渴望的方法),如果栏可以永久隐藏,请纠正我!!! 我在这里附加了用于隐藏该栏的代码,但是每当我点击屏幕时,该栏就会重新出现。

而是可以获取Android底部软件导航栏的高度,以便相应地调整页面元素的位置吗? (更令人遗憾的是,某些Android设备允许用户通过单击工具栏上的箭头按钮来手动显示和隐藏该工具栏。)

//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.

在此处输入图片说明 遗憾的是,DeviceDisplay.MainDisplayInfo.Height包含导航栏的高度,否则我不需要执行上述操作。 没有软件导航栏,是否可以检测屏幕高度?

非常感谢您对此提供的任何帮助。

PS:除了获取高度以外,我是否至少可以检测软件导航栏是否打开/显示? 现在我知道我可以使用ViewConfiguration.Get(Android.App.Application.Context).HasPermanentMenuKey来检测设备是否具有硬导航键,这很有用,但是我仍然无法检测到软导航栏是否处于打开状态。

关于在xamarin.form中获取导航栏高度,您可以尝试使用:

 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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