On Android 4.0 and Lower
In AndroidManifest.xml -> inside the activity which you want to use, add the following to hide the status bar:
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
Programatically, by setting WindowManager flag:
Write a helper function
void hideStatusBar() {
// For Android version lower than Jellybean, use this call to hide the status bar.
if (Build.VERSION.SDK_INT < 16) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
Use the helper function in onCreate()
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideStatusBar();
// We should never show the action bar if the status bar is hidden, so hide that too
//if necessary.
getSupportActionBar().hide() // if you have extended the activity from support lib like Appcompat, else use getActionBar().hide() here
setContentView(R.layout.activity_main);
}
Please Note:
- onCraete() will not get called always, so If you want system UI changes to persist as the user navigates in and out of your activity, set UI flags in onResume() or onWindowFocusChanged().
- Use it before super.onCreate(savedInstanceState); if it crash
Find more details from here