2014-09-28 350 views
0

我嘗試使用下面的代碼隱藏我的活動android的狀態欄:隱藏Android狀態欄中

Status Bar I want to hide

的OnCreate代碼:

// set as full screen 
    View decorView = getWindow().getDecorView(); 
    // Hide the status bar. 
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; 
    decorView.setSystemUiVisibility(uiOptions); 

protected void onResume() { 
    super.onResume(); 
    // set as full screen 
    View decorView = getWindow().getDecorView(); 
    // Hide the status bar. 
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; 
    decorView.setSystemUiVisibility(uiOptions); 
} 

protected void onWindowFocusChanged() { 
    // set as full screen 
    View decorView = getWindow().getDecorView(); 
    // Hide the status bar. 
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; 
    decorView.setSystemUiVisibility(uiOptions); 
} 

的狀態欄隱藏,直到我選擇菜單(下面的代碼菜單):

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    if (item.getItemId() == R.id.help) { 
     homehelp = 0; // reset the homehelp logic 
     homehelp(); // call it to display 
    } 
    return false; 
} 

任何使菜單膨脹的選項都會顯示狀態欄 - 狀態欄會一直保留,直到我使用電源關閉/打開或騎自行車離開我的活動強制執行簡歷。

有人可以提供一個建議如何保持與菜單通貨膨脹/選擇隱藏狀態欄?

謝謝;

安迪

+0

你可以添加的究竟是什麼狀態欄你的意思的形象嗎? – user2235615 2014-09-28 08:22:15

回答

0

嘗試

public boolean onOptionsItemSelected(MenuItem item) { 
    if (item.getItemId() == R.id.help) { 
     homehelp = 0; // reset the homehelp logic 
     homehelp(); // call it to display 
    } 

    // set as full screen 
    View decorView = getWindow().getDecorView(); 
    // Hide the status bar. 
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; 
    decorView.setSystemUiVisibility(uiOptions); 

    return false; 
} 
+0

如果我從菜單中選擇某些東西,如果我不從菜單中選擇任何東西,然後狀態欄仍然存在 – andy 2014-09-28 09:08:36

+0

我可不確定你可以做什麼,但在oncreateoptionmenu中嘗試它,因爲狀態欄出現在菜單循環後已被切換 – 2014-10-01 17:26:22

0

嘗試

public void onWindowFocusChanged(boolean winChange){ 
     super.onWindowFocusChanged(winChange); 

     if(winChange){ 
      View decorView = getWindow.getDecorView(); 
      int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; 
      decorView.setSystemVisibility(uiOptions) 
     } 
} 
+0

由於您的問題很短,您可能還會添加更多信息 - 您解釋得越多,其他人就越容易幫助您。祝你好運! – Tristan 2015-12-04 04:06:40