fun setStatusBarTransparent() {
window.apply {
addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowCompat.setDecorFitsSystemWindows(window, true)
}
}
完成上面的代码后,状态栏和导航栏都变得透明并与ui重叠。 我想保留状态栏在上面,并确保导航栏不透明并且不与ui重叠。 我该怎么办?
这是有线的,因为现在建议您实现边缘到边缘。
如果有帮助的话,试试这个:
// Before setContentView in onCreate
enableEdgeToEdge(
navigationBarStyle = SystemBarStyle.dark(Color.DARK)
)
// Then after setContentView
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
val inset = insets.getInsets(WindowInsetsCompat.Type.systemBars())
// Make your root view padding the DARK navigationbar so that it will not cover your view content.
v.updatePaddingRelative(
bottom = inset.bottom
)
// Other insets handling...
// Make your appbar fit system bars
// Or set it via xml with fitSystemWindows=true
insets
}