有人知道如何在使用 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));
关于android - 使用 windowTranslucentStatus = true 时摆脱 Android L 自动不透明色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30431482/