gpt4 book ai didi

android - 如何创建一个完全透明的导航栏?

转载 作者:行者123 更新时间:2023-11-29 15:42:34 29 4
gpt4 key购买 nike

我想将导航栏更改为完全透明,如下图所示。

我试过了 <item name="android:windowTranslucentNavigation">true</item>但它不是完全透明的(更像是 50%)。

有解决办法吗?因为我什么也没发现,但我看到一些像 Nova 这样使用它的应用程序。它甚至在谷歌指南中https://material.google.com/layout/structure.html#structure-system-bars

Transparent Nav

最佳答案

我的灵感来自 Google Keep 应用,它具有如下所示的类似实现:

enter image description here

所以我试图找到一篇关于如何实现这件事的合适帖子,但不幸的是什么也没找到,而且上面的答案也不起作用。所以我决定尝试所有与 navigationBar Android Studio 建议相关的标志。

让我详细解释一下:

  1. 只有 android:navigationBarColor 在您使用浅色主题时不会执行任何操作。但在深色主题上,它会起作用。

  2. windowTranslucentNavigation 设置为 true 会做两件事:

    • 在软导航栏下方绘制 Activity
    • 覆盖 navigationBarColor 并强制其透明。

如下图所示:

enter image description here

  1. 如果您使用 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS(按照@Frankenxtein 的回答),您将得到以下结果:

enter image description here

这在某种程度上接近了预期的结果,但这并不是因为它在导航栏下方绘制了 Activity 组件。而且它还会弄乱你的填充和边距(参见完整屏幕截图 here )。而且,您必须为每个 Activity 执行此操作,还必须调整当前 margin 。

解决方案

这可以在不影响当前布局的情况下实现。要在深色主题中执行此操作,您没有问题,只需设置 android:navigationBarColor 即可。

然而,我们的目标是使用浅色主题 let (#FFFFFF)。使用需要 API 27 或更高版本的 android:windowLightNavigationBar 以及 android:navigationBarColor 将得到我们想要的结果。

<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
<item name="android:windowLightNavigationBar">true</item>

我的应用案例 colorPrimaryDark 在浅色主题中是#FFFFFF,在深色主题中是德古拉,你也可以为此声明一个新变量。产生以下结果:

浅色主题 enter image description here

深色主题

enter image description here

这里 android:navigationBarColor 设置导航栏的背景颜色。和 android:windowLightNavigationBar 设置深色按钮颜色并指示背景是浅色的,正如您可以从它的名称中理解的那样。

希望对您有所帮助!

关于android - 如何创建一个完全透明的导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38161472/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com