不推荐使用android.view.View.systemUiVisibility.什么是替代品? [英] android.view.View.systemUiVisibility deprecated. What is the replacement?

查看:1799
本文介绍了不推荐使用android.view.View.systemUiVisibility.什么是替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将项目目标API版本更新为30,现在我发现不赞成使用systemUiVisibility属性.

I have updated the project target API version to 30, and now I see that the systemUiVisibility property is deprecated.

下面的kotlin代码是我正在使用的代码,它实际上等效于

The following kotlin code is the one I'm using which is actually equivalent to setSystemUiVisibility method in Java.

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,但是我不怎么做.

Please let me know if you have got any stable replacement for this deprecated code. The google's recommendation is to use WindowInsetsController, but I don't how to do that.

推荐答案

希望对您有所帮助.

以前,在实施边缘到边缘导航或沉浸式模式时,要采取的第一步措施是使用systemUiVisibility标志,以要求将应用全屏显示, 这个新的Android版本不赞成使用此字段,并且要全屏布局应用,您必须在Window类上使用新方法:setDecorFitsSystemWindowsfalse传递为如下所示的参数.

Previously, when implementing edge-to-edge navigation or immersive mode, one of the first steps to take was to use the systemUiVisibility flags in order to request the app to be laid out fullscreen, This new Android release deprecates this field and in order to layout the app fullscreen you have to use a new method on the Window class: setDecorFitsSystemWindows passing false as an argument like below.

window.setDecorFitsSystemWindows(false)

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

WindowInsetsController class which allows you to do things that previously were controlled via systemUiVisibility flags, like hiding or showing the status bar or navigation bar(hide and show methods, respectively)

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

For example, you can easily show and hide the keyboard as shown below:

// 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())
}

这篇关于不推荐使用android.view.View.systemUiVisibility.什么是替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆