簡體   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