提问者:小点点

Android.View.View.SystemUIvisibility已弃用。 替代的是什么?


我已经将项目目标API版本更新为30,现在我看到systemUiVisibility属性已被弃用。

下面的kotlin代码就是我使用的代码,它实际上相当于Java中的setSystemUiVisibility方法。

playerView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LOW_PROFILE
            or View.SYSTEM_UI_FLAG_FULLSCREEN
            or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)

请让我知道,如果你有任何稳定的替代这个不推荐使用的代码。 谷歌的建议是使用WindowInsetsController,但我不知道怎么做。


共1个答案

匿名用户

希望能帮到你。

以前,当实现边缘到边缘导航或沉浸式模式时,首先要采取的步骤之一是使用systemUiVisibility标志来请求应用程序全屏布局,这个新的Android版本不推荐使用该字段,并且为了使应用程序全屏布局,您必须在window类上使用一个新方法:SetDecorFitssSystemWindows传递false作为参数,如下所示。

window.setDecorFitsSystemWindows(false)

WindowInSetsController类,它允许您执行以前通过SystemUIVisibility标志控制的操作,例如隐藏或显示状态栏或导航栏(分别为hide和show方法)

例如,您可以轻松地显示和隐藏键盘,如下所示:

// You have to wait for the view to be attached to the
// window (otherwise, windowInsetController will be null)
view.doOnLayout {
    view.windowInsetsController?.show(WindowInsets.Type.ime())
    // You can also access it from Window
    window.insetsController?.show(WindowInsets.Type.ime())
}