How To Detect Full Screen Gesture Mode In Android 10
Solution 1:
You can use below code to check gesture or navigation mode
publicstaticintisEdgeToEdgeEnabled(Context context) {
Resourcesresources= context.getResources();
intresourceId= resources.getIdentifier("config_navBarInteractionMode", "integer", "android");
if (resourceId > 0) {
return resources.getInteger(resourceId);
}
return0;
}
The value that returned by isEdgeToEdgeEnabled function will follow below:
Solution 2:
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.
intgestureLeft=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.
Solution 3:
According to docs, there is a hasInsets()
method that returns true
if the WindowInsets
has any nonzero insets.
https://developer.android.com/reference/android/view/WindowInsets#hasInsets()We can use it this way
view.rootWindowInsets.hasInsets()
Hope this helps!
Post a Comment for "How To Detect Full Screen Gesture Mode In Android 10"