Search code examples
androidandroid-actionbarandroid-notification-bar

How can I keep the action/title bar but hide the notification bar


How can I keep the action/title bar but hide the notification bar?

This question looks like it has already been answered but most of the answers I found hide both the action bar and the notification bar. I want to be able to keep the action/title bar. The best I've gotten is hiding both and using a linear layout to display a custom action/title bar but I want a system generated one. Also is it possible to hide just the action bar whilst displaying the notification bar?


Solution

  • To hide the notification bar use the follow code:

    WindowManager.LayoutParams attrs = act.getWindow().getAttributes();
    attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    act.getWindow().setAttributes(attrs);
    

    To show the notification bar use the follow code:

    WindowManager.LayoutParams attrs = act.getWindow().getAttributes();
    attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    act.getWindow().setAttributes(attrs);
    

    You'd probably want to call the code in Activity.onCreate().