hide and show statusbar without any effect to layout in android
Asked Answered
W

1

0

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

Whitehouse answered 1/12, 2014 at 8:6 Comment(0)
W
0

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);
Whitehouse answered 6/12, 2014 at 10:46 Comment(1)
what is mSystemUiVisibility in showSystemUI method ?Inglenook

© 2022 - 2024 — McMap. All rights reserved.