2015-11-14 217 views
7

如何隱藏特定活動的狀態欄?如何隱藏狀態欄?

我發現了這個類似的問題,但沒有答案爲我工作。該應用程序剛剛墜毀,每次我試圖去活動: How to hide status bar in Android

謝謝。

+0

http://stackoverflow.com/questions/33692388/android-remove-actionbar-title-keeping-toolbar-menu/33692402#33692402 –

+0

狀態欄就是我想要去除,不行動起來吧。 – user5495265

回答

15

設置你的內容之前,試試這個在您的活動

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
+0

這工作,但它適用於所有版本的Android? – user5495265

+0

是的,它會適用於所有版本的Android –

3

隱藏在Android 4.0的狀態欄和下

  1. 通過設置應用程序的主題中manifest.xml文件。

    android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" 
    

    OR

  2. 通過活動的onCreate()方法編寫Java代碼。

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        // If the Android version is lower than Jellybean, use this call to hide 
        // the status bar. 
        if (Build.VERSION.SDK_INT < 16) { 
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
           WindowManager.LayoutParams.FLAG_FULLSCREEN); 
        } 
        setContentView(R.layout.activity_main); 
    } 
    

隱藏在Android 4.1的狀態欄和更高

通過活動的onCreate()方法編寫Java代碼。

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(); 
1
if (Build.VERSION.SDK_INT < 16)//before Jelly Bean Versions 
{ 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
         WindowManager.LayoutParams.FLAG_FULLSCREEN); 
} 
else // Jelly Bean and up 
{ 
    View decorView = getWindow().getDecorView(); 
    // Hide the status bar. 
    int ui = View.SYSTEM_UI_FLAG_FULLSCREEN; 
    decorView.setSystemUiVisibility(ui); 

    //Hide actionbar 
    ActionBar actionBar = getActionBar(); 
    actionBar.hide(); 
}