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



我正在研究相关的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"/> 

您可以做到这一点:

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);

或查看此发布的问题:禁用通知面板被拉下来

最新更新