Detection if the navigation bar is located directly on the screen

I just need to determine if the navigation bar is to the right of the screen, as shown in the image below. Thanks

screenshot with navbar to the right

+3
source share
3 answers

The following snippet may help:

private boolean isNavigationBarRightOfContent(){
    Rect outRect = new Rect();
    ViewGroup decor = (ViewGroup) mActivity.getWindow().getDecorView();
    decor.getWindowVisibleDisplayFrame(outRect);
    DisplayMetrics dm = getResources().getDisplayMetrics();
    return dm.widthPixels == outRect.bottom;
}
+2
source

The navigation bar will only be located to the right of the screen if it is in landscape mode. To detect this, use getResources().getConfiguration().orientationas follows:

String orientation = getResources().getConfiguration().orientation;
if(orientation.equals("ORIENTATION_LANDSCAPE"){
    // screen in landscape, do what you want to do
}
+1
source

Try the following:

    // 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;
0
source

All Articles