9

I run my app on Tablet, which has both status bar (on top of screen) and navigation bar (on bottom of screen). I use this code to make Activity Full screen.

 public void hideNavigationBar() {
    final View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(setSystemUiVisibility());

}

public static int setSystemUiVisibility() {
    return 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
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}

Then when I touch a Button, I want to show a PopupMenu. The problem is: when PopupMenu is shown, the status bar and navigation bar appear.

I tried to add this line:

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

It works for the status bar. But the navigation bar still appears when show PopupMenu.

How can I keep full screen when show PopupMenu?

EDIT: Here is the code where I show the PopupMenu:

    ImageView btnOpen = (ImageView) findViewById(R.id.image_view_open);
    btnOpen.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu popupMenu = new PopupMenu(ActivityViewImage.this, v);
            getMenuInflater().inflate(R.menu.context_menu_image, popupMenu.getMenu());
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    //do something
                    return true;
                }
            });
            popupMenu.show();
        }
    });
TOP
  • 2,574
  • 5
  • 35
  • 60

3 Answers3

0

TOP you can try to this code hope this can help you..

 @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}
Dileep Patel
  • 1,988
  • 2
  • 12
  • 26
0

Just call your hideNavigationBar() when the popup menu disappears. You can do this in your main activity like this (code in kotlin):

override fun onWindowFocusChanged(hasFocus: Boolean) {
    if (hasFocus) hideNavigationBar()
    super.onWindowFocusChanged(hasFocus)
}
Oleg Yablokov
  • 736
  • 8
  • 19
0

I could not accomplish the exact behavior but making activity full screen immediately after context menu closed worked fine for my use case.

override fun onContextMenuClosed(menu: Menu) {
    super.onContextMenuClosed(menu)
    fullScreen()
}

this is the fullscreen method i used:

fun Activity.fullScreen() {
    if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
        val v = this.window.decorView
        v.systemUiVisibility = View.GONE
    } else if(Build.VERSION.SDK_INT >= 19) {
        //for new api versions.
        val decorView = window.decorView
        val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_FULLSCREEN or
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        //original code from stackOverFlow: View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        decorView.systemUiVisibility = uiOptions
    }
}
Amir
  • 318
  • 1
  • 5
  • 11