Hide Notification bar

后端 未结 9 1553
[愿得一人]
[愿得一人] 2020-11-27 03:17

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: Plea

相关标签:
9条回答
  • 2020-11-27 03:57

    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);
    
    0 讨论(0)
  • 2020-11-27 03:58

    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

    0 讨论(0)
  • 2020-11-27 04:00

    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

    0 讨论(0)
  • 2020-11-27 04:01
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    
    0 讨论(0)
  • 2020-11-27 04:09

    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);
        }
    }
    
    0 讨论(0)
  • 2020-11-27 04:09

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

    0 讨论(0)
提交回复
热议问题