我正在开发一个应用程序,我想在用户端禁用状态栏,并在管理员使用时启用。我已成功使用以下代码禁用状态栏:
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;
// PrefUtils.setKioskModeActive(false, getApplicationContext());
view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
但是我无法再次启用状态栏。这可以使用此代码重新启用。或任何其他方式来禁用/启用状态栏。 在此先感谢!。
答案 0 :(得分:0)
@Kaifi你应该从WindowManager
删除相同的视图:
((WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE)).removeView(YOUR_VIEW);
或者作为:
manager.removeView(YOUR_VIEW);