2017-08-30 37 views
1

我正在考試相關的android應用程序。當考試開始時,我需要鎖定狀態欄和通知欄。我使用下面的代碼,但它只是隱藏狀態欄和通知欄。如何在我的應用程序的特定活動中鎖定狀態欄和通知欄

this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

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

是否有任何方法來鎖定狀態欄和通知欄,而不是隱藏它們。對於任何積極的答覆,提前致謝。

回答

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

+0

我需要停止用戶訪問時,他們出席的通知考試。完成考試後,他們可以打開通知 –

+0

查看我更新的答案。 – Orvenito

+0

你可能還需要這個:[link](https://gist.github.com/sarme/7e4dc90e2478ade310e6) – Orvenito

相關問題