Fullscreen Activity in Android?

后端 未结 30 2254
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 00:12

How do I make an activity full screen? I mean without the notification bar. Any ideas?

30条回答
  •  一生所求
    2020-11-22 01:01

    To make your activity full screen do this:

        // add following lines before setContentView
        // to hide toolbar
                    if(getSupportActionBar()!=null)
                        getSupportActionBar().hide();
        //to hide status bar
                    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    

    This will hide the toolbar and status bar.

    But In some case, you may want to show status bar with a transparent background, in that case, do this:

    // add following lines before setContentView
    // to hide toolbar
    if(getSupportActionBar()!=null)
       getSupportActionBar().hide();
    // to make status bar transparent
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    

    Some other alternate to hide toolbar instead of getSupportActionBar().hide():

    1. Remove toolbar by changing the app theme's parent: