Android 如何在我的应用程序中的特定活动中锁定状态栏和通知栏

Android 如何在我的应用程序中的特定活动中锁定状态栏和通知栏,android,statusbar,android-notification-bar,Android,Statusbar,Android Notification Bar,我正在开发一个与考试相关的android应用程序。当考试开始时,我需要锁定状态栏和通知栏。我使用了下面的代码,但它只是隐藏状态栏和通知栏 this.requestWindowFeature(Window.FEATURE_NO_TITLE); //Remove notification bar this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutPara

我正在开发一个与考试相关的android应用程序。当考试开始时,我需要锁定状态栏和通知栏。我使用了下面的代码,但它只是隐藏状态栏和通知栏

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        //Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

是锁定状态栏和通知栏而不是隐藏它们的任何方法。对于任何积极响应,请提前感谢。

锁定通知栏是什么意思?你的意思是暂时没有收到任何通知

关于你的问题。您可以做的是使工具栏不可单击,或者更具体地说,使导航抽屉不可单击,以便用户无法打开它

编辑:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> 

或者看下面的问题:

我需要阻止用户在参加考试时访问通知。完成考试后,他们可以打开通知您可能还需要:我收到以下错误:无法添加窗口android.view.ViewRootImpl$W@2e63dab--拒绝对窗口类型2010的权限
WindowManager manager = ((WindowManager) getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE));

WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|

            // this is to enable the notification to recieve touch events
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |

            // Draws over status bar
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

    localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    localLayoutParams.height = (int) (50 * getResources()
            .getDisplayMetrics().scaledDensity);
    localLayoutParams.format = PixelFormat.TRANSPARENT;

    customViewGroup view = new customViewGroup(this);

    manager.addView(view, localLayoutParams);