弹出菜单显示时隐藏导航栏

时间:2017-01-06 10:53:03

标签: java android popup navigationbar popupmenu

我的应用程序以全屏模式运行。下面的代码隐藏导航栏。

   public static void hideDefaultControls(@NonNull final Activity activity) {
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        final Window window = activity.getWindow();

        if (window == null) {
            return;
        }

        final View decorView = window.getDecorView();

        if (decorView != null) {
            int uiOptions = decorView.getSystemUiVisibility();

            if (Build.VERSION.SDK_INT >= 14) {
                uiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
            }

            if (Build.VERSION.SDK_INT >= 16) {
                uiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            }

            if (Build.VERSION.SDK_INT >= 19) {
                uiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            }

            decorView.setSystemUiVisibility(uiOptions);
        }
    }

android.widget.PopupMenu;

PopupMenu popupMenu = new PopupMenu(context, anchor);

//init code...
popupMenu.show();

我希望在弹出菜单显示时有全屏模式。我在显示弹出窗口后尝试调用hideDefaultControls()方法,但只有在隐藏弹出窗口后才会隐藏控件。

0 个答案:

没有答案