美文网首页
Android实现沉浸式

Android实现沉浸式

作者: imkobedroid | 来源:发表于2020-05-30 11:30 被阅读0次

代码

半沉浸式加下面代码

  <style name="ImmersionTheme"  parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowNoTitle">true</item>
    </style>

但这是5.1的系统,当切换到6.0以后的系统的时候,导航栏阴影很明显,所以需要加以下动态代码

动态代码

全沉浸式加下面代码

 fun hideStatusBar(activity: Activity) {
        val window: Window = activity.window
        window.clearFlags(
            WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
        )
        window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        window.statusBarColor = Color.TRANSPARENT
        window.navigationBarColor = Color.TRANSPARENT
    }

相关文章

网友评论

      本文标题:Android实现沉浸式

      本文链接:https://www.haomeiwen.com/subject/tfuczhtx.html