如何实现从应用栏到状态栏的无缝过渡

发布于 2025-01-18 12:21:12 字数 1092 浏览 0 评论 0原文

因此,我目前正在尝试迁移应用程序以一致地使用 Material 3。此前它是拼接在一起的,没有任何真正的设计概念。现在我想让自己看起来真正严肃起来。

我无法弄清楚的一件事是如何使状态栏与标题栏具有相同的颜色。目前它看起来像这样:

问题截图

然而,官方文档在 “新增内容”部分

示例

我目前正在使用 LinearLayoutTheme.Material3.DayNight 主题(暂时没有任何修改),并且从我需要的文档中学到的内容在 CoordinatorLayout 内的 AppBarLayout 中使用诸如 MaterialToolbar 之类的组件,以便一切按预期工作。我尝试这样做,滚动和提升现在可以按照文档中的描述进行工作,但不幸的是状态栏的颜色保持不变。

我现在不确定我的期望是否错误或者我的代码是否错误。我相信必须有一种内置机制可以自动调整状态栏的颜色以动态匹配应用程序栏的颜色。但我可能是错的,material-components-android 希望我自己实现逻辑。无论如何,有人可以向我指出一个无缝过渡的示例实现吗?这样我就可以修改我的代码来实现这种行为。

我目前正在使用 com.google.android.material:material:1.5.0 以防这与问题相关。

提前致谢!

So I'm currently trying to migrate an app to use Material 3 consistently. Previously it was stiched together without any real design concept. Now I want to actually look like something to take serious.

One thing I haven't been able to figure out is how to give the status bar the same color as the title bar. Currently it looks like this:

Screenshot of problem

The official documentation however lists the seamless version in the "What's new" section:

Example

I'm currently using a LinearLayout with the Theme.Material3.DayNight theme (without any modifications for now) and from what I was able to learn from the documentation I need to make use of components like MaterialToolbar inside a AppBarLayout inside a CoordinatorLayout so everything works as intended. I tried doing that and the scrolling and lifting now works as described in the documentation, but the color of the status bar remains unchanged unfortunately.

I'm not sure at this point if my expectations are wrong or if my code is. I believe that there has to be a built-in mechanism that automatically adjusts the status bar's colour to dynamically match the one of the app bar. I might be wrong though and the material-components-android expects me to implement the logic myself. In any case, could someone point me towards an example implementation where this transition is seamless? This way I could modify my code to implement this behaviour.

I'm currently using com.google.android.material:material:1.5.0 in case this is relevant to the problem.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文