gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:56:59 24 4
gpt4 key购买 nike

我在一个显示 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com