How do I make an activity full screen? I mean without the notification bar. Any ideas?
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()
:
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
For kotlin lovers, why not use extension functions:
For first case:
fun AppCompatActivity.makeItFullScreenStatusBarVisible(){
supportActionBar?.hide()
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
And call this before setContentView
:
makeItFullScreenStatusBarVisible()
For Second One:
fun AppCompatActivity.makeItFullScreenStatusBarHidden(){
supportActionBar?.hide()
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
And call it before setContentView
:
makeItFullScreenStatusBarHidden()