如何实现从应用栏到状态栏的无缝过渡
因此,我目前正在尝试迁移应用程序以一致地使用 Material 3。此前它是拼接在一起的,没有任何真正的设计概念。现在我想让自己看起来真正严肃起来。
我无法弄清楚的一件事是如何使状态栏与标题栏具有相同的颜色。目前它看起来像这样:
然而,官方文档在 “新增内容”部分:
我目前正在使用 LinearLayout
和 Theme.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:
The official documentation however lists the seamless version in the "What's new" section:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论