android - 使用 windowTranslucentStatus = true 时摆脱 Android L 自动不透明色调

标签 android android-5.0-lollipop android-4.4-kitkat android-statusbar

有人知道如何在使用 windowTranslucentStatus = true 时摆脱这种自动色调吗?我已经将状态栏颜色设置为透明,但是当我启用 windowTranslucentStatus 时,它似乎会覆盖它。如果我禁用 windowTranslucentStatus,那么我会获得所需的状态栏颜色,但我无法再在状态栏下绘制抽屉导航。我能够使用 ScrimInsetFrameLayout 实现我想要的目标,但这导致了其他问题。

enter image description here

最佳答案

如果启用FLAG_TRANSLUCENT_STATUS,您可以在状态栏下绘制,因为它会自动设置两个其他系统 UI 可见性标志,如 documentation 中所述。 :

public static final int FLAG_TRANSLUCENT_STATUS

When this flag is enabled for a window, it automatically sets the system UI visibility flags SYSTEM_UI_FLAG_LAYOUT_STABLE and SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN.

由于您只想使用setStatusBarColor,因此您需要手动设置这些标志:

int flag = window.getDecorView().getSystemUiVisibility();
window.getDecorView().setSystemUiVisibility( flag | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
window.setStatusBarColor(context.getResources().getColor(R.color.yourcolor));

关于android - 使用 windowTranslucentStatus = true 时摆脱 Android L 自动不透明色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30431482/

相关文章:

java - 整个应用程序的 LibGDX 公共(public) Sprite 批处理

android - apprestart 后 SQLCipher 无法打开数据库

android - 新的 Android Material 设计中的 Action Bar(Toolbar) 图标应该有多大?

android - 如何在不同的 Activity 调用上执行不同的功能?

android - SQLite 中 "not equal"的语法是什么?

android - 在卸载 Android 2.3 时删除应用程序外部文件

android - Flexbox 在 Android 4.4.2 的 Android Web 浏览器中不工作

android - 如何检查是否为目录路径授予了权限并且不会出现 EACCES 错误?

android - 自定义操作栏布局中按钮的 sherlock 操作项样式

android - mhtml 文件无法在 Lollipop 和棉花糖的 webview 中正确加载/显示,但在 Lollipop 之前的设备上