Hide Notification bar
Asked Answered
F

8

54

Anyone know how to disable/hide notification bar at the top which show battery and other things in android. Any help will be appreciated.

EDIT: Please also add how can I hide ActionBar+NotificationBar for later android versions.

Fabled answered 19/11, 2010 at 6:40 Comment(3)
Are you sure your users want you to?Chug
@Martin: I would even pay for this.Homburg
The first two answers, hide ActionBar too. If you intend to only hide notification bar, see my answer.Protagoras
C
85

You could use a theme in your AndroidManifest.xml:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

or change parent of your AppTheme to @android:style/Theme.NoTitleBar.Fullscreen like this

<style name="AppTheme" parent="Theme.NoTitleBar.Fullscreen">
</style>

then apply this theme on activities which you want Fullscreen like

android:theme="@style/AppTheme"

or use the following code snippet:

public class FullScreen
    extends android.app.Activity
{
    @Override
    public void onCreate(android.os.Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);
    }
}
Chug answered 19/11, 2010 at 8:36 Comment(4)
The java code does not hide the notification bar for me. The theme, however, worked great.Bourdon
Thanks Martin, for both approaches.Fabled
You don't need to request FEATURE_NO_TITLE. Setting the fullscreen flags is enough for hiding the notification bar. Thus you can still use the action bar AND hide the notification bar.Smashup
If you do not intend to hide ActionBar too, have a look at this answer: https://mcmap.net/q/334976/-hide-notification-barProtagoras
P
32

The answers above hide ActionBar too. If you intend to only hide notification bar, use this code:

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

be careful to put it before setContentView().

Protagoras answered 11/11, 2013 at 9:6 Comment(1)
This is the best way i ever find. :)Irmgard
U
21
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
Unquestioning answered 19/11, 2010 at 8:35 Comment(0)
T
6

Another Simple option is to add <item name="android:windowFullscreen">true</item> on the theme you will apply to activities that don't need a notification bar...

like so..

<style name="AppTheme.Splash">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

Works like charm

Tangent answered 15/10, 2018 at 6:38 Comment(1)
worked for me. better than add deprecated flagsEarshot
C
2

Successfully implemented a slightly modified version of @Martin's suggestion along with a custom theme to get rid of BOTH the Status and Navigation Bar.

public class MyActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //* Hides Notification Bar
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_my);
}

Top part is used to get rid of the Status bar. Add the following code to your @styles as a resource to kill off the NavBar as well.

 <resources> <style name="NoNav" parent="@android:style/Theme.Holo.Light">
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style> </resources>

After you add this to your resource file, pop open AndroidManifest.xml and chance your application theme to "@style/NoNav".

Android UI bloatware eliminated :)

Coadjutress answered 14/10, 2014 at 9:27 Comment(0)
C
1

You can use this for 4.1 or upper versions.

View decorView = getWindow().getDecorView();    
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Childers answered 5/11, 2015 at 21:35 Comment(2)
It hides the status bar but I can still see the color primary dark.Lockman
@SrikarReddy try to remove android:fitsSystemWindows="true" at your xml layout file you are inflating into your activity. For me it helped.Sirois
P
0

you can do like this in onCreate() method :

View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getActionBar();
actionBar.hide();
Prissie answered 18/5, 2018 at 8:58 Comment(0)
I
0

This answer is for android developers who like minimalist and simplified one-liner code. If you intend to only hide notification bar, use this code:

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

be careful to put it before setContentView() in your on create() function of required activity.class

Irmgard answered 17/3, 2020 at 10:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.