gpt4 book ai didi

WindowInsetsController#hide(statusBars()) causes content to jump(WindowInsetsController#Hide(statusBars())导致内容跳转)

转载 作者:bug小助手 更新时间:2023-10-25 16:57:50 34 4
gpt4 key购买 nike



At the moment my activity calls

在我的活动召唤的那一刻


requestWindowFeature(Window.FEATURE_NO_TITLE)
window.setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN)

inside of its onCreate method in order to hide the status bar and display in fullscreen mode.

在其onCreate方法内部,以隐藏状态栏并以全屏模式显示。


As part of the migration to Android 30 I replace window.setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN) with WindowInsetsController#hide(statusBars()) as documentation suggests. However, the behaviour of these two approaches is not the same. While the deprecated one smoothly hides the status bar the modern one makes the content of the activity to "jump" when the status bar is hidden.

作为向Android 30迁移的一部分,正如文档所建议的那样,我用WindowInsetsController#Hide(statusBars())替换了window.setFlages(FLAG_FullScreen,FLAG_FullScreen)。然而,这两种方法的行为并不相同。当状态栏被隐藏时,不推荐使用的版本会平滑地隐藏状态栏,而最新的版本则会使活动的内容“跳转”。


Has anybody observed the same behaviour and found a fix for it?

有没有人观察到同样的行为,并找到了解决办法?


更多回答
优秀答案推荐

I'm not sure if it fits your specific purpose since I had to rework my code a lot for a satisfactory solution, but I managed to get rid of the "jumping" with the following code in my Activity (I use the Compat classes to avoid having to code multiple implementations, but the original classes work the same):

我不确定它是否适合您的特定目的,因为我不得不重新编写代码以获得满意的解决方案,但我在活动中设法消除了以下代码的“跳跃”(我使用Compat类来避免编写多个实现,但原始类的工作方式相同):


@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideSystemUI();
}
}

private void hideSystemUI() {
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

WindowInsetsControllerCompat insetsController = WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
if (insetsController != null) {
insetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
insetsController.hide(WindowInsetsCompat.Type.statusBars());
insetsController.hide(WindowInsetsCompat.Type.navigationBars());
}
}

I had a toggling solution before which showed the system and navigation bar on touch (quite similar to the now deprecated documentation, but I was not able to make it work without jumping.

我之前有一个切换解决方案,它显示触摸的系统和导航栏(与现在不推荐使用的文档非常相似,但我无法让它不跳转就能工作)。


What made the difference for me was to use WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE. The documentation about this option says the following:

对我来说与众不同的是使用了WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE.有关此选项的文档说明如下:



These transient system bars will overlay app’s content, may have some degree of transparency, and will automatically hide after a short timeout.



By the way, since the official documentation still uses deprecated code as of today I marked it as "unusable documentation" down below in the hope that it will get updated sooner.

顺便说一句,由于官方文档到今天为止仍然使用不推荐使用的代码,我在下面将其标记为“不可用文档”,希望它能尽快更新。



Kotlin version used in my app

我的应用程序中使用的Kotlin版本


`

`


private fun setToFullScreen() {
WindowCompat.setDecorFitsSystemWindows(window, false)

val insetsController = WindowCompat.getInsetsController(window, window.decorView)
insetsController.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
insetsController.hide(WindowInsetsCompat.Type.statusBars())
insetsController.hide(WindowInsetsCompat.Type.navigationBars())
}

`

`


更多回答

In the end I developed almost the same solution

最后,我开发了几乎相同的解决方案

I have noticed the 'jumping' when using the hide/show in portrait orientation. In landscape orientation, there is no 'jumping'. The transient showing of bars solution is not good enough for me, because I want more customization. It looks like you can use the hide/show solution and still keep the window flags for fullscreen and avoid the jumping. In landscape mode, using fullscreen mode with hide/show messes up. So I am thinking of using fullscreen flag in portrait, and resetting the flags in landscape.

我注意到了在肖像方向上使用Hide/Show时的跳跃。在横向,没有‘跳跃’。BAR解决方案的短暂显示对我来说不够好,因为我想要更多的定制。看起来您可以使用隐藏/显示解决方案,同时仍然保留全屏窗口标志并避免跳转。在横向模式下,使用全屏模式和隐藏/显示会搞砸。所以我正在考虑在肖像中使用全屏旗帜,并在风景中重置旗帜。

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