根据应用栏的材质3规格,不仅应用栏本身,状态栏也应该在滚动应用栏下的列表时调整其颜色。如何实现这一目标?我们应该在每个屏幕中手动执行此操作吗? https://m3.material.io/components/top-app-bar/guidelines
在您希望状态栏适应其颜色的每个屏幕中,您可以手动处理此行为。使用
WindowInsetsController
和 getWindowInsetsController()
方法。此方法从Android 11开始可用:
// Obtain an instance of the WindowInsetsController
val windowInsetsController = window?.insetsController
// Set the appearance of the system bars
windowInsetsController?.setSystemBarsAppearance(APPEARANCE_STABLE_TOP, APPEARANCE_STABLE_TOP)
// For example, you can listen to the scroll events and update the appearance flags accordingly