android - 如何在我的应用程序中的特定 Activity 中锁定状态栏和通知栏

标签 android statusbar android-notification-bar

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

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

或查看此发布的问题:Disable the notification panel from being pulled down

关于android - 如何在我的应用程序中的特定 Activity 中锁定状态栏和通知栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45956749/

相关文章:

javascript - 禁用浏览器状态栏文本

android - 在android中处理多个通知

android - FLAG_ACTIVITY_CLEAR_TOP 在通知部分不起作用

android - 如何将底部应用栏与顶部应用栏配对?

php - 如何查看Mysql表有没有变化?

android - 延迟显示图像在android中使用位图

android - 在android应用程序中,在android Manifest文件中给coreApp ="true"有什么用?为什么在 Honey Comb 之前不需要它?

ios - 即使出现警报也隐藏状态栏

objective-c - 如何移动屏幕上的导航栏位置