簡體   English   中英

Android:檢查屏幕上是否有其他操作按鈕(主頁,后退等)?

[英]Android : check wether action button (home,back, etc.. ) is inside the screen or not?

我想更詳細地解釋,

一些android設備具有這樣的操作按鈕, 在此處輸入圖片說明

雖然某些設備具有

在此處輸入圖片說明

在第一種情況下,所有動作按鈕都在屏幕外,而在第二種情況下,動作按鈕位於屏幕底部(在屏幕內)...我如何檢測到該動作按鈕在哪里? 我對此一無所知..!

查看Android官方文檔: http : //developer.android.com/reference/android/view/KeyCharacterMap.html#deviceHasKey%28int%29

deviceHasKey方法將解決您的問題。 (使用鍵碼KEYCODE_MENU,KEYCODE_HOME,KEYCODE_BACK)。 希望能幫助到你。

也許通過在您的onCreate()進行以下檢查:

適用於api 14及更高版本

boolean PermanentMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey(); // true if physical, false if virtual

對於較低的api:

boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);

if (hasBackKey && hasHomeKey) {
    // no navigation bar, unless it is enabled in the settings
} else {
    // 99% sure there's a navigation bar
}

您可以在這里得到答案。 檢查導航欄

ps該欄的正式名稱是“導航欄”
https://developer.android.com/training/system-ui/navigation.html

這里找到了解決方案,但不是100%保證所有設備都能正常工作,某些設備(例如HTC,LAVA等)無法正常工作。 minApi還需要13 + ... !!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM