gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 16:29:42 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com