简体   繁体   中英

i have to block status bar and home navigation bar. i used below code to block it

 private void hideSystemUI() {

 View decorView = getWindow().getDecorView();

 int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
 | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
 | View.SYSTEM_UI_FLAG_IMMERSIVE;

  decorView.setSystemUiVisibility(uiOptions);
   }

and also:

@Override

public void onWindowFocusChanged(boolean hasFocus)
{

 super.onWindowFocusChanged(hasFocus);

  View decorView = getWindow().getDecorView();

  decorView.setOnSystemUiVisibilityChangeListener( 
        newView.OnSystemUiVisibilityChangeListener() {

         @Override

         public void onSystemUiVisibilityChange(int i) {

            if (i == View.VISIBLE){
                hideSystemUI();
            }
            else {
                hideSystemUI();
            }
        }
    });

wrote the hidesystemUI() code in onCreate() and onResume() also, including with decorView.setOnSystemUiVisibilityChangeListener(). So i have to block it. Once i swipe at the top, it is coming and going back ( like a blink). But i have to block it. Once we swipe at the top it should not appear. help me out of this.

If you do not want it to blink, you may delay hiding. For example, you can give it a 2 seconds delay by Handler.postDelayed() .

private void hideSystemUI() {
    final int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE;

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            getWindow().getDecorView().setSystemUiVisibility(uiOptions);
        }
    }, 2000); //2 seconds delay
}

If you are always calling this on the main thread, you can simply call new Handler() to return a Handler on the main thread. Otherwise, you will need to call new Handler(Looper.getMainLooper()) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM