我只需要检测导航栏是否位于屏幕右侧,如下图所示。谢谢。
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;
}
ViewCompat.setOnApplyWindowInsetsListener(
window.decorView
) { _: View, windowInsets: WindowInsetsCompat ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
if (insets.bottom > 0) {
// Navigation Bar at Bottom
} else if (insets.right > 0) {
// Navigation Bar at Right
} else if (insets.left > 0) {
// Navigation Bar at Left
}
WindowInsetsCompat.CONSUMED
}
Try this:
// 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;
getResources().getConfiguration().orientation
:String orientation = getResources().getConfiguration().orientation;
if(orientation.equals("ORIENTATION_LANDSCAPE"){
// screen in landscape, do what you want to do
}