Android - Making activity full screen with status bar on top of it

I want to make my activity full screen with status bar on top of it like this picture:

enter image description here

I have used this code in manifest inside activity tag:

'android:theme="@style/Theme.AppCompat.Light.NoActionBar"'

But my view doesn't start from the status bar & it looks like this:

enter image description here

How can I make my activity look like the first one?


I know that the guy asking the question may have found his own solution but for the people who are still looking for a solution this is a very simple solution but one thing it has a limitation till Kitkat so a condition is added

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                      WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

Add these to your Base Application Theme in styles.xml

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

And add following attribute to your parent layout:

android:fitsSystemWindows="false"

Hope this helps.


If you dont want your "Translucent navigation" transparent, here is the code to just make transparent the status bar

In your theme:

    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowTranslucentStatus">true</item>

In your activity onCreate:

Window window = getWindow();
WindowManager.LayoutParams winParams = window.getAttributes();
winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
window.setAttributes(winParams);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

1. Transparent Statusbar

window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
window.statusBarColor = Color.TRANSPARENT

enter image description here

2. Transparent Statusbar & Bottomnav bar

    window.setFlags(
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
    );

enter image description here

3. Hide Statusbar

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        window.insetsController?.hide(WindowInsets.Type.statusBars())
    }
    else {
        @Suppress("DEPRECATION")
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
    }

enter image description here

4. Hide Statubar & Bottomnav bar

val actionBar: ActionBar? = supportActionBar
          if (actionBar != null) actionBar.hide()
         window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LOW_PROFILE
            or View.SYSTEM_UI_FLAG_FULLSCREEN
            or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)

enter image description here

where to put this code ?

   override fun onCreate(savedInstanceState: Bundle?) {

        /*  Put above code here ..... */
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_slider)
   }

Note

  • I checked this code in Pixel 3A emulator
  • Maybe customise android OS not support
  • set styel <style name="Theme.FullScreen" parent="Theme.MaterialComponents.DayNight.NoActionBar">