android - 带有手势导航的错误 snackbar 位置

标签 android android-studio user-interface android-10.0

我在一个显示 Snackbar 的应用程序上工作.
这个Snackbar在我的 MainActivity 中使用以下代码可以正常工作:

Snackbar snackbar = Snackbar.make(myLayout, "My snackbar", Snackbar.LENGTH_LONG)
                .setBackgroundTint(myColor)
                .setTextColor(ContextCompat.getColor(this, R.color.black));
[...]
snackbar.show();
这是显示:
enter image description here
它适用于每个方向的每个屏幕和不同的 Android 版本。只有一种配置会出错:当设备使用手势导航时。 (这么多新手机)
在这种情况下,Snackbar显示 Snackbar 之间的差距和屏幕底部是这样的:
enter image description here
我在网上没有找到任何解释,但我自己找到了这个。
通过打开 Show layout bounds在开发者选项中,我们可以观察到“经典”导航栏看起来仍然在这里,就好像可见性设置为 View.INVISIBLE我们可以期待View.GONE无论屏幕如何。
所以,当我尝试显示 Snackbar ,它就出现在这个“隐形导航栏”的顶部。
这是一些带有和不带有手势导航的布局边界的屏幕(在主菜单中):
enter image description here
enter image description here
这是使用不同的手机和品牌(Pixel、Samsung ...)甚至模拟器进行的测试。
有正常行为吗?我怎样才能抑制这个差距?

最佳答案

对我来说设置GestureInsetBottomIgnoredtrue修复了问题:

snackbar.setGestureInsetBottomIgnored(true);
来自 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.

关于android - 带有手势导航的错误 snackbar 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63705222/

相关文章:

java - Android Studio,缺少android.support.annotation包

Android 图表与其他内容在同一页面中

java - Google Analytics - 强制屏幕跟踪

android - OnResume/OnPause 被多次调用

java - 为什么DDMS不再开放?

java.util.ConcurrentModificationException 从数组列表中删除元素时,即使使用迭代器

java - GUI - 如何在保存用户输入的同时在面板或框架之间切换

c# - 横向旋转 TreeView

android - Surface 在 Android 应用程序上无效

android - 如何在android中更改pivotX,pivotY?