Android: show/hide status bar/power bar

后端 未结 9 1149
梦如初夏
梦如初夏 2020-12-07 20:03

I am trying to create a button where I can hide or show the status bar on my tablet.

I\'ve put in the onCreate

getWindow().addFlags(WindowManager.Lay         


        
9条回答
  •  粉色の甜心
    2020-12-07 21:05

    For Some People, Showing status bar by clearing FLAG_FULLSCREEN may not work,

    Here is the solution that worked for me, (Documentation) (Flag Reference)

    Hide Status Bar

    // Hide Status Bar
    if (Build.VERSION.SDK_INT < 16) {
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    else {
       View decorView = getWindow().getDecorView();
      // Hide Status Bar.
       int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
       decorView.setSystemUiVisibility(uiOptions);
    }
    

    Show Status Bar

       if (Build.VERSION.SDK_INT < 16) {
                  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        else {
           View decorView = getWindow().getDecorView();
          // Show Status Bar.
           int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
           decorView.setSystemUiVisibility(uiOptions);
        }
    

提交回复
热议问题