android - 带有 BottomSheetDialog 的半透明导航栏
问题描述
BottomSheetDialog
当我边到边时,我正在为 targetSdk=30 上的正确导航栏着色而战。我在这里通过代码设置了灯光导航栏选项:
override fun onAttachedToWindow() {
super.onAttachedToWindow()
val window = window
?: error("window not attached?!")
val sheetView = findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
?: error("bottom sheet design not found")
WindowInsetsControllerCompat(window, sheetView).apply {
isAppearanceLightNavigationBars = true
}
ViewCompat.setOnApplyWindowInsetsListener(sheetView) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
sheetView.updatePadding(
bottom = insets.bottom
)
sheetView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = -insets.bottom
}
WindowInsetsCompat.CONSUMED
}
}
在我的主题中,我有这个
<style name="BottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="enableEdgeToEdge">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
正如预期的那样,这会产生一个完全透明的导航栏(毕竟导航栏的颜色是透明的)。但是,当我尝试使导航栏半透明时,即通过给它“#40ffffff”的颜色或通过设置android:windowTranslucentNavigation
,导航栏保持透明,没有应用稀松布/背景保护。我究竟做错了什么?
解决方案
推荐阅读
- python - 数据采集和绘图在单独的线程中
- javascript - 如何将数组中的特定元素合并在一起?
- php - Laravel Nova 未按记录显示 userTimezone
- reactjs - 样式化组件需要什么严格类型?
- java - 关于 SQL Server jdbc 的字符串长度限制?
- python - 如何与python TCP协议进行外部交互
- javascript - 如何更改倒计时的显示?
- javascript - 如何在 Slick Slider 的第一张幻灯片中制作一行,在所有其他幻灯片中制作两行?
- javascript - Yargs 中的命令函数
- python-3.3 - python 3从字符串中删除所有新行标记