2017-01-09 74 views
0

我用SYSTEM_UI_FLAG_FULLSCREEN隱藏status bar,這樣的代碼(SDK> 16):隱藏狀態欄不工作

Decorview decorview = getWindow().getDecorview(); 
decorview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); 

但是,它適用於一些Android手機,但無法在其他類似如下: wrong status bar hidden

白色satus吧有什麼問題?爲什麼不隱藏? ps:風格很好,只是一個正常的,沒有fitwindowsystem,沒有身臨其境。

+0

嗨,你有沒有找到答案呢?我有同樣的問題。 –

+0

@AI WId Nope。我放棄了使用這種方法,並使用如下方式:getWindow()。addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);有用。 –

+0

好的謝謝,我會做同樣的我想 –

回答

0

由於在Android Docs提到的,你可以隱藏statusBar像這樣的SDK < 16即Android版本比傑利貝恩低:在您的onCreate方法

if (Build.VERSION.SDK_INT < 16) { 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     } 

調用此,你叫setContentView之前。

和用於SDK以上16使用以下代碼:

View decorView = getWindow().getDecorView(); 
// Hide the status bar. 
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; 
decorView.setSystemUiVisibility(uiOptions); 
// Remember that you should never show the action bar if the 
// status bar is hidden, so hide that too if necessary. 
ActionBar actionBar = getActionBar(); 
actionBar.hide(); 
+0

感謝您的回覆!但是sdk在16以上,並沒有操作欄。我只是做你的答案,但它在某些電話上失敗。 –

0

1.如果Android版本比傑利貝恩較低,使用這個調用來隱藏。

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if (Build.VERSION.SDK_INT < 16) { 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    } 
    setContentView(R.layout.activity_main); 
} 

2.Code隱藏在16和更高的代碼工作的狀態欄。

Decorview decorview = getWindow().getDecorview(); 
decorview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); 

注:請記住,你永遠不應該顯示操作欄,如果狀態欄是隱藏的,所以隱藏太多,如果必要的。

ActionBar actionBar = getActionBar(); 
actionBar.hide(); 

3.如果在狀態欄應該總是保持隱藏在你的應用程序設置在應用程序的清單文件中的一個活動主題。

<application 
    ... 
    android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" > 
    ... 
</application> 
+0

感謝您的回覆!但是sdk在16以上,並沒有操作欄。我只是做你的答案,但它在某些電話上失敗 –