简体   繁体   中英

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

i would like to explain in more detail,

some of android device have action button like this, 在此处输入图片说明

while some of device have like,

在此处输入图片说明

in first case all action button is outside the screen while in second case action button is given bottom of screen(inside the screen)... how can i detect that where the action button is present? i have no idea about it..!!

Check the official Android docs : http://developer.android.com/reference/android/view/KeyCharacterMap.html#deviceHasKey%28int%29

The method deviceHasKey will solve your problem. (Use Keycodes KEYCODE_MENU, KEYCODE_HOME, KEYCODE_BACK). Hope it helps.

Maybe by doing the following check in your onCreate() :

for api 14 and up

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

for lower 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
}

You may get your answer here. Check for navigation bar

ps The formal name of the bar is "Navigation Bar"
https://developer.android.com/training/system-ui/navigation.html

found solution here , but not 100% guarantee to work for all device, some device like HTC, LAVA etc not working with that. Also minApi required 13+ for that...!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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