android - 如何在Xamarin.Form应用程序中获取Android底部软件导航栏的高度?

标签 android xamarin.forms xamarin.android

我很困惑,在不同的文档中,导航栏指的是不同的控件,但在这里,它是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.

enter image description here奇怪的是,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);

关于android - 如何在Xamarin.Form应用程序中获取Android底部软件导航栏的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57170764/

相关文章:

Android: "Cannot Resolve symbol ' addValueEventListener'"在 Firebase 中

c# - 是否有处理 PIN 输入的 xamarin 组件?

c# - Azure 移动应用程序 - 自定义身份验证 - 无法登录

c# - Xamarin 未处理的异常无法从程序集中加载 MainActivity

c# - 运算符 && 不能应用于 decimal 和 decimal 类型的操作数

android - 执行完成后关闭 Realm 实例

java - Android HTTPPOST 执行 PHP 脚本两次

c# - 该方法已弃用 "palette.generate"来自 android 支持库

android - 在 android recyclerview 中一次仅捕捉一项,而不捕捉更多项目

c# - Xamarin 表单(Android): OnCreate bundle is null