12

How can I hide the status bar for a specific activity?

I found this similar question, but none of the answers worked for me. The app just crashed every time I tried to go to the activity: How to hide status bar in Android

Thanks.

2

5 Answers 5

23

Try this in you activity before setting your content

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
Sign up to request clarification or add additional context in comments.

1 Comment

That worked, but does it work for all versions of Android?
4

Hide the Status Bar on Android 4.0 and Lower

  1. By setting the theme of application in manifest.xml file.

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

    OR

  2. By writing JAVA code in activity's onCreate() method.

    @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); } 

Hide the Status Bar on Android 4.1 and Higher

By writing JAVA code in Activity's onCreate() method.

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(); 

Comments

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(); } 

2 Comments

Not working for me on Android 9... The app is in Full Screen but the statusBar shows up. Any idea ?
Please add these before setContentView in OnCreate if (Build.VERSION.SDK_INT >= 21) { Window window = this.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(ContextCompat.getColor(this, R.color.toolbar_color)); }
0

Only working answer (for me at least)

In styles.xml

<resources> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> ... </style> </resources> 

The in-code solution did not work for me in 4.4.2 Kitkat.

Comments

-1

Open styles.xml and update the styles which your activity uses :

<style name="ExampleTheme" parent="android:Theme.Light"> <item name="android:windowNoTitle">true</item> <!-- add this line --> </style> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.