hide and show statusbar without any effect to layout in android

3.2k views Asked by At

I want to write a book-reader application that normally runs in full-screen, but when user touched screen, status bar become visible OVER my main layout without re-creating the whole view. I already read these but no help at all:

Hide notification bar without using fullscreen Hide Notification bar Android Show Activity Title/status bar at the top after it is hidden

any idea how can I do it?

thanks

1

There are 1 answers

1
Mohammad Zarei On BEST ANSWER

finally, I did it!! these 2 methods will show and hide status bar without destroying the layout. you need to set

private View mMainView; // The main view of the activity

private int mSystemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;

then

    /** Hides StatusBar and ActionBar */
private void hideSystemUi() {

    ActionBar ab = getActionBar();
    ab.hide();

    // Set flags for hiding status bar
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    // Hide the status bar.
    mMainView.setSystemUiVisibility(uiOptions);}

and

   /** Shows StatusBar and ActionBar */
private void showSystemUi() {
    ActionBar ab = getActionBar();
    ab.show();
    // Reset flags 
    mMainView.setSystemUiVisibility(this.mSystemUiVisibility);
}

and put this in your onCreate() method:

mMainView = findViewById(R.id.mainLayout);
mMainView.setSystemUiVisibility(mSystemUiVisibility);