是否可以让系统栏重叠而不与导航栏重叠

问题描述 投票:0回答:1
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重叠。 我该怎么办?

android kotlin uinavigationbar statusbar navigationbar
1个回答
0
投票

这是有线的,因为现在建议您实现边缘到边缘。
如果有帮助的话,试试这个:

// 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
}

© www.soinside.com 2019 - 2024. All rights reserved.