Something that worked well for me - I hope this helps those who come back to this in the future.
You can use the Handler to change flags after the overflow menu appears. On my devices, the back button is still displayed, but the black navigation bar is not visible (disappears before it appears visually).
// Creates the PopupMenu. PopupMenu popup = new PopupMenu(getContext(), view) { @Override public void show() { // Shows the menu. super.show(); // Sets the UI flags to prevent weird changing of window. Handler temp = new Handler(); temp.postDelayed(new Runnable() { @Override public void run() { getWindow().getDecorView().setSystemUiVisibility( 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); } }, 50); } }
source share