Skip to content Skip to sidebar Skip to footer

Hide And Show Statusbar Without Any Effect To Layout In Android

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 who

Solution 1:

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 activityprivateint mSystemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;

then

/** Hides StatusBar and ActionBar */privatevoidhideSystemUi() {

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

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

and

/** Shows StatusBar and ActionBar */privatevoidshowSystemUi() {
    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);

Post a Comment for "Hide And Show Statusbar Without Any Effect To Layout In Android"