这个重叠导航栏的原因是 MaterialDatePicker
默认为全屏显示,除非有自定义样式,例如这个答案所示。但这也不是你想要的,因为它会像一个浮动对话框。
为了解决这个问题,你需要通过将 true 传递给 WindowCompat.setDecorFitsSystemWindows
来改变选择器窗口不适应其内容视图到窗口插图。如需详细信息,请参阅文档。
但是,这也会影响状态栏的顶部插图,所以现在它看起来就像透明的;因此,你必须更改它的颜色以匹配选择器头背景的颜色。
以下是示例:
val picker = MaterialDatePicker.Builder.dateRangePicker().build()
picker.show(supportFragmentManager, "tag")
// Delay is used to give the dialog a chance to build as it would
// return null unitl it's shown. MaterialDatePicker is a final class;
// so, this wouldn't be embedded in a custom extended class.
Handler(Looper.getMainLooper()).postDelayed({
picker.dialog?.window?.apply {
WindowCompat.setDecorFitsSystemWindows(this, true)
statusBarColor = ResourcesCompat.getColor(resources,
R.color.purple_500, /* default dialog head color */
null)
}
}, 100)
fitsSystemWindows
设置为true和透明导航栏。 - DrHowdyDoo