gpt4 book ai didi

android.view.View.systemUiVisibility 已弃用。什么是替代品?

转载 作者:行者123 更新时间:2023-12-02 11:43:11 47 4
gpt4 key购买 nike

我已将项目目标 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 ,但我不知道该怎么做。

最佳答案

为了兼容性,请使用 WindowCompatWindowInsetsControllerCompat .您需要升级 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
对于显示屏顶部有凹槽的设备,您可以将以下内容添加到您的 v27 theme.xml文件使 UI 出现在缺口的两侧:
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
您可以通过以下链接阅读更多信息: Display Cutout

关于android.view.View.systemUiVisibility 已弃用。什么是替代品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62577645/

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