I found this article really useful in explaining what WindowInsets
are and how to use them.
Basically I check if the left gesture inset is greater than 0
, and if it is then the system is using gesture type navigation. Left and right gesture insets have to be greater than 0
in gesture type navigation because you swipe from the right or left to go back.
int gestureLeft = 0;
if (Build.VERSION.SDK_INT >= 29) {
gestureLeft = this.getWindow().getDecorView().getRootWindowInsets().getSystemGestureInsets().left;
}
if (gestureLeft == 0) {
// Doesn't use gesture type navigation
} else {
// Uses gesture type navigation
}
Obviously, the window has to be rendered for this to work. You can add it inside an OnApplyWindowInsetsListener
if you want this to run as soon as the window is rendered.
Note: I tried using getSystemGestureInsets().bottom
, but it returned a non-zero value even when I wasn't using gesture type navigation.