如何根据appbar自动给Android的状态栏着色

问题描述 投票:0回答:1

根据应用栏的材质3规格,不仅应用栏本身,状态栏也应该在滚动应用栏下的列表时调整其颜色。如何实现这一目标?我们应该在每个屏幕中手动执行此操作吗? https://m3.material.io/components/top-app-bar/guidelines

android material-design material3
1个回答
0
投票

在您希望状态栏适应其颜色的每个屏幕中,您可以手动处理此行为。使用

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
© www.soinside.com 2019 - 2024. All rights reserved.