我正在研究与考试相关的Android应用程序。考试开始时我需要锁定状态栏和通知栏。我使用下面的代码,但它只隐藏状态栏和通知栏。
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
是否可以锁定状态栏和通知栏而不是隐藏它们。对于任何积极的回应,请提前感谢。
答案 0 :(得分:2)
你是什么意思锁定通知栏?你的意思是暂时没有收到任何通知?
关于你的问题。您可以做的是使您的工具栏无法点击或更具体地使导航抽屉无法点击,因此用户无法打开它。
编辑:
<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