简体   繁体   English

Android。 立即隐藏状态栏

[英]Android. Hide status bar without delay

I am trying to hide the status bar.我正在尝试隐藏状态栏。 This is my code:这是我的代码:

 window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
 actionBar?.hide()

The status bar is hidden, but the behavior is not quite expected.状态栏是隐藏的,但行为并不完全是预期的。 Suppose I have 2 activities.假设我有 2 个活动。 Activity A and Activity B. Activity A has a green status bar, and activity B needs to hide the status bar.活动A和活动B。活动A有一个绿色的状态栏,活动B需要隐藏状态栏。 In Activity B, I call the code to hide the status of the bar in onCreate() before performing the setContentView().在活动 B 中,我在执行 setContentView() 之前调用代码以在 onCreate() 中隐藏栏的状态。 As a result, when switching to activity B, the green status bar is displayed for the first few seconds, and only after it is hidden.因此,当切换到活动 B 时,绿色状态栏会在最初的几秒钟内显示,并且只有在它隐藏之后才会显示。 I need the status bar to be hidden immediately upon transition to activity B.我需要在转换到活动 B 后立即隐藏状态栏。

User this in you Java Files OnCreate Method requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);在你使用这个 Java 文件OnCreate方法requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

In your Activity B, you just need to set android:fitsSystemWindows="true" in your MaterialToolbaror CollapsingToolbarLayout.在您的 Activity B 中,您只需在 MaterialToolbar 或 CollapsingToolbarLayout 中设置android:fitsSystemWindows="true"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM