作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已将项目目标 API 版本更新为 30,现在我看到 systemUiVisibility 属性已被弃用。
以下 kotlin 代码是我正在使用的代码,它实际上等同于 setSystemUiVisibility 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)
如果您对此已弃用的代码有任何稳定的替代品,请告诉我。 google 的建议是使用
WindowInsetsController
,但我不知道该怎么做。
最佳答案
为了兼容性,请使用 WindowCompat
和 WindowInsetsControllerCompat
.您需要升级 androidx.core
的 gradle 依赖项至少到 1.6.0-alpha03
以便支持setSystemBarsBehavior
在 SDK < 30 上。
private fun hideSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, mainContainer).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
private fun showSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, true)
WindowInsetsControllerCompat(window, mainContainer).show(WindowInsetsCompat.Type.systemBars())
}
您可以找到有关
WindowInsets
的更多信息通过观看
YouTube video
theme.xml
文件使 UI 出现在缺口的两侧:
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
您可以通过以下链接阅读更多信息:
Display Cutout
关于android.view.View.systemUiVisibility 已弃用。什么是替代品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62577645/
我是一名优秀的程序员,十分优秀!