fun setTranslucentActionBar(window: Window) { val window = 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_STABLE window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) window.decorView.fitsSystemWindows = true window.statusBarColor = Color.TRANSPARENT } //建议使用此方法 fun transparentStatusBar( window: Window) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) val option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN val vis = window.decorView.systemUiVisibility window.decorView.systemUiVisibility = option or vis window.statusBarColor = Color.TRANSPARENT } else { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) } }
Android 透明状态栏
于 2024-01-26 20:35:01 首次发布
本文介绍了如何在Android应用中使用funsetTranslucentActionBar和transparentStatusBar方法来设置透明状态栏和导航栏,针对不同版本的API调整参数,实现沉浸式UI效果。
摘要由CSDN通过智能技术生成