Search code examples
androidandroid-studiouser-interfaceandroid-10.0

Wrong snackbar position with gesture navigation


I work on an app which display a Snackbar.

ThisSnackbar working fine with the following code in my MainActivity:

Snackbar snackbar = Snackbar.make(myLayout, "My snackbar", Snackbar.LENGTH_LONG)
                .setBackgroundTint(myColor)
                .setTextColor(ContextCompat.getColor(this, R.color.black));
[...]
snackbar.show();

Here is the display:

enter image description here

It working fine for every screen on every orientation and for different Android versions. For only one configuration it bugs: when the device use gesture navigation. (So lot of new phones)

In this case, Snackbar is dispayed with a gap between the Snackbar and the bottom of the screen like this:

enter image description here

I did not find any explanation on the web but I found this by myself.

By switching on the Show layout bounds options in Developer options, we can observe that the "classic" navigation bar looks like still here as if the visibility was set to View.INVISIBLE where we can expect View.GONE whatever the screen.

So, when I try to display the Snackbar, it appears just on top of this "invisible navigation bar".

Here is some screen with layout bounds with and without gesture navigation (in home menu):

enter image description here

enter image description here

This was test with different phone and brand (Pixel, Samsung ...) and even with emulator.

Is there a normal behavior? How can I suppress this gap?


Solution

  • For me setting GestureInsetBottomIgnored to true fixed the issue:

    snackbar.setGestureInsetBottomIgnored(true);
    

    From the Android Docs:

    Sets whether this bottom bar should adjust it's position based on the system gesture area on Android Q and above. Note: the bottom bar will only adjust it's position if it is dismissable via swipe (because that would cause a gesture conflict), gesture navigation is enabled, and this gestureInsetBottomIgnored flag is false.