导航栏在沉浸式模式下显示在PopupMenu上

时间:2017-05-31 11:20:47

标签: android

我正在创建一个带有弹出菜单的相机应用程序,用于某些相机设置。问题是,当我点击显示弹出菜单的按钮时,会出现底部导航栏。我已经在网上搜索了一个解决方案,但到目前为止还没有为我工作。

mChangeSettingsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            final PopupMenu changeSettingsPopupMenu = new PopupMenu(Camera2VideoImageActivity.this, mChangeSettingsButton) {
                @Override
                public void show() {

                    getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
                    super.show();

                    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);


                    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

                }


            };changeSettingsPopupMenu.getMenuInflater().inflate(R.menu.change_setting_popup_menu, changeSettingsPopupMenu.getMenu());

            SubMenu changeImageResolutionSubMenu = changeSettingsPopupMenu.getMenu().addSubMenu(0, 100, 0, "Set Image Resolution ");
            SubMenu changeVideoResolutionSubMenu = changeSettingsPopupMenu.getMenu().addSubMenu(0, 101, 0, "Set Video Resolution");
            changeSettingsPopupMenu.show();
}

我的主要活动也有这个:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        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);
    }

<iframe src="https://giphy.com/embed/3oKIPh2W4bEQrGzmqQ" width="272" height="480" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/3oKIPh2W4bEQrGzmqQ">via GIPHY</a></p>

GIF发生了什么: http://gph.is/2rjPdny

编辑: 感谢Hitesh Gehlot的回复!我尝试时得到这个。 This didn't work, Click to view image

1 个答案:

答案 0 :(得分:-1)

试试这个:

changeSettingsPopupMenu.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        changeSettingsPopupMenu.getWindow().getDecorView().setSystemUiVisibility(getWindow().getDecorView().getSystemUiVisibility());
 changeSettingsPopupMenu.show();