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

Get rid of Android L automatic opacity tint when using windowTranslucentStatus = true

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

如果您启用 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));