【发布时间】:2021-12-23 15:19:24
【问题描述】:
我有三个片段。我想在一个片段上应用透明状态栏。为此,我在底部导航栏的setOnItemSelectedListener 方法上调用了以下隐藏方法。还添加了我现在得到的图像
private fun hideStatusBar() {
window.statusBarColor = ContextCompat.getColor(this@SuperActivity, R.color.transparent)
WindowCompat.setDecorFitsSystemWindows(window, false)
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars())
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.left
rightMargin = insets.right
bottomMargin = insets.bottom
}
WindowInsetsCompat.CONSUMED
}
}
private fun showStatusBar() {
window.statusBarColor = ContextCompat.getColor(this@SuperActivity, R.color.transparent)
WindowCompat.setDecorFitsSystemWindows(window, true)
}
但是当我点击另一个片段(需要显示状态栏的片段)时,我得到以下行为:
【问题讨论】:
-
您是否将这个
WindowCompat.setDecorFitsSystemWindows(window, false)还原为其他片段? -
是的。正如您在 showStatusBar() 方法中看到的那样。我使用 WindowCompat.setDecorFitsSystemWindows(window, true) 恢复了这个
标签: android android-fragments android-bottomnavigationview windowinsets