Is there a way to know where this Navigation Bar will be displayed for landscape :
Thanks
Android already has a rotate button in the quick settings menu which lets you set the screen's orientation to portrait, landscape, or auto-rotate.
Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.
Based in part on Pauland's answer (in turn based on the implementation of PhoneWindowManager
), here is what I am using at the moment:
public static boolean isSystemBarOnBottom(Context ctxt) { Resources res=ctxt.getResources(); Configuration cfg=res.getConfiguration(); DisplayMetrics dm=res.getDisplayMetrics(); boolean canMove=(dm.widthPixels != dm.heightPixels && cfg.smallestScreenWidthDp < 600); return(!canMove || dm.widthPixels < dm.heightPixels); }
This works on a Nexus 7 2012 and a Nexus 4, each running Android 5.1.
On devices that have a permanent MENU key, there is no system bar. Depending upon your use case, you may need to check for this case:
ViewConfiguration.get(ctxt).hasPermanentMenuKey()
(where ctxt
is some Context
)
Personally, I am using this to try to have a sliding panel be on the opposite axis from the system bar, as bezel swipes on the side with the system bar are a bit difficult to trigger. I would not use this, or any other algorithm (like the ones that depend upon getDecorView()
), for anything critical.
By using the properties of the decor view in combination with the current DisplayMetrics you can find out on which side the navigation bar is positioned.
// retrieve the position of the DecorView Rect visibleFrame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(visibleFrame); DisplayMetrics dm = getResources().getDisplayMetrics(); // check if the DecorView takes the whole screen vertically or horizontally boolean isRightOfContent = dm.heightPixels == visibleFrame.bottom; boolean isBelowContent = dm.widthPixels == visibleFrame.right;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With