How to keep full screen when show popup menu?
Asked Answered
S

3

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();
        }
    });
Symposium answered 2/12, 2016 at 4:20 Comment(2)
have you tried this one #34395416Combustion
Try this: getSupportActionBar().hide();Dispensatory
B
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);
    }
}
Breaking answered 2/12, 2016 at 6:1 Comment(1)
It doesn't work, sir. When I show PopupMenu, the navigation bar still appearsSymposium
C
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)
}
Connotative answered 21/9, 2020 at 15:23 Comment(0)
N
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
    }
}
Northnorthwest answered 13/10, 2020 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.