美文网首页
Android透明状态栏

Android透明状态栏

作者: 丶Castiel | 来源:发表于2021-01-26 10:31 被阅读0次
    protected fun transparentStatusBar(activity: Activity) {
            if (Build.VERSION.SDK_INT >= 21) {
                val window: Window = activity.window
                //添加Flag把状态栏设为可绘制模式
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
                window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
                window.statusBarColor = Color.TRANSPARENT
                //view不根据系统窗口来调整自己的布局
                val mContentView = window.findViewById(Window.ID_ANDROID_CONTENT) as ViewGroup
                val mChildView = mContentView.getChildAt(0)
                if (mChildView != null) {
                    ViewCompat.setFitsSystemWindows(mChildView, false)
                    ViewCompat.requestApplyInsets(mChildView)
                }
            }else{
                window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
            }
        }
    

    相关文章

      网友评论

          本文标题:Android透明状态栏

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