2017-06-01 78 views
0

我有一個全屏的活動。我正在使用下面的代碼(我在onResume方法中調用)進行全屏活動:關閉Android PopUpWindow對象使狀態欄可見。如何阻止此?

int currentApiVersion = Build.VERSION.SDK_INT;

final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
      | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
      | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 
      | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
      | View.SYSTEM_UI_FLAG_FULLSCREEN 
      | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 

    // This work only for android 4.4+ 
    if (currentApiVersion >= Build.VERSION_CODES.KITKAT) { 
     activity.getWindow().getDecorView().setSystemUiVisibility(flags); 
     // Code below is to handle presses of Volume up or Volume down. 
     // Without this, after pressing volume buttons, the navigation bar will 
     // show up and won't hide 
     final View decorView = activity.getWindow().getDecorView(); 
     decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { 
      @Override 
      public void onSystemUiVisibilityChange(int visibility) { 
       if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { 
        decorView.setSystemUiVisibility(flags); 
       } 
      } 
     }); 
    } 

在這個活動中,我打開了一個PopUpWindow對象。但打開後,狀態欄變得可見。如何阻止此?

對於表示PopUpWindow,我使用下面的代碼:

popupWindow =新PopupWindow(佈局,RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT,TRUE); popupWindow.showAtLocation(layout,Gravity.NO_GRAVITY,0,0);

我無法弄清楚,這些方法有什麼問題。請幫忙。提前致謝。

回答

1

變更實施方式和對ActivityonCreate使用這個代碼,讓你setContentView()之前已經加入此肯定一件事OnCreate

@Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      requestWindowFeature(Window.FEATURE_NO_TITLE); 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

      setContentView(R.layout.splash_layout); 
    } 
+0

是的,它的工作。謝謝。 –