6

I am using following code to hide status bar,

if (Build.VERSION.SDK_INT < 16) {
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
}

It works but

  1. when the Activity starts it shows a white background at top for a couple of seconds. Is there any way to avoid that?
  2. Does anybody know how to hide it with animation (Moving upwards) like Whatsapp hides status bar when you click on Status image?
  3. If I show a ProgressDialog or AlertDialog and then dismiss it and come back to Activity then the status bar becomes visible again. How to avoid it so that status bar remains invisible always?
Guri
  • 61
  • 2

2 Answers2

0

For those who fight with this issue, use the following code:

if (Build.VERSION.SDK_INT < 16) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); }

Charlesjean
  • 566
  • 1
  • 5
  • 16
-1
  1. Make sure you are finishing the previous activity after starting new activity. If you call finish() before startActivity() it is chance of getting white screen. (OR) If white screen appears in launcher activity it is because of enabling Insta Run in Android Studio. Refer this link about Insta Run.

  2. For Whats App like animation you have to do create your layout with coordinator layout , collapsing toolbar. Using parallax scrolling effect you can hide image as like whats app. For tutorial refer here link

  3. After calling AlertDialog your activity is Resumes, so you hide the status bar on OnCreate() only if you open any dialogs and back to activity it is called OnResume() in this the super.onResume will called and the activities basic will reset again. So you call that status bar hide method in OnResume() method also.

Naveen Kumar M
  • 7,497
  • 7
  • 60
  • 74