Created
July 12, 2018 14:37
-
-
Save thanhit93/d4721d99d3ced12d37af03a999f2fc29 to your computer and use it in GitHub Desktop.
Check nav bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WindowManager mgr = (WindowManager) getSystemService(WINDOW_SERVICE); | |
boolean hasSoftKey = Utils.hasSoftKeys(mgr, NPTApplication.this); | |
public static boolean hasSoftKeys(WindowManager windowManager, Context c) { | |
boolean hasSoftwareKeys = true; | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | |
Display d = windowManager.getDefaultDisplay(); | |
DisplayMetrics realDisplayMetrics = new DisplayMetrics(); | |
d.getRealMetrics(realDisplayMetrics); | |
int realHeight = realDisplayMetrics.heightPixels; | |
int realWidth = realDisplayMetrics.widthPixels; | |
DisplayMetrics displayMetrics = new DisplayMetrics(); | |
d.getMetrics(displayMetrics); | |
int displayHeight = displayMetrics.heightPixels; | |
int displayWidth = displayMetrics.widthPixels; | |
hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; | |
} else { | |
boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey(); | |
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); | |
hasSoftwareKeys = !hasMenuKey && !hasBackKey; | |
} | |
return hasSoftwareKeys; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://sharecoding.wordpress.com/2016/08/23/detect-navigation-bar-or-get-its-height-in-android/