hide and show statusbar without any effect to layout in android

廉价感情. 提交于 2019-12-25 03:15:38

问题


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:


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);


来源:https://stackoverflow.com/questions/27224106/hide-and-show-statusbar-without-any-effect-to-layout-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!