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

AndroidAndroid ActivityAndroid ThemeAndroid FullscreenAndroid Statusbar

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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);
}

Solution 2 - Android

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.

Solution 3 - Android

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);

Solution 4 - Android

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">

Solution 5 - Android

put below of code inside onCreate()

private void setStatusBarTransparent() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        View decorView = window.getDecorView();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
        window.setStatusBarColor(Color.TRANSPARENT);
    }
}

Solution 6 - Android

enter image description here To achieve something similar to this, use this:

1. Your Activity Theme

<style name="FullScreenTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowActivityTransitions">true</item>
</style>

2. There is NO NEED to add android:fitsSystemWindows property into your root layout XML file.

3. In your Activity

Add padding top to your toolbar. I am using custom toolbar, so I am adding padding to my toolbar of the height of statusbar.

toolbar.setPadding(0, getStatusBarHeight(), 0, 0)

and the function getStatusBarHeight() is added in my Utils class

fun Activity.getStatusBarHeight(): Int {
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
return if (resourceId > 0) resources.getDimensionPixelSize(resourceId)
else Rect().apply { window.decorView.getWindowVisibleDisplayFrame(this) }.top

}

Solution 7 - Android

Try Like This

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

Hope this one will help

Solution 8 - Android

In Kotlin just use following code in your activity, also add android:fitsSystemWindows="true" in your parent view of activity.xml layout file. This will also show content over navigation bar too, provided you declared full screen style in your style.xml

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
     window.setFlags(
            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
        )
    }

Solution 9 - Android

you can use this code after onCreate

   setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }

your activity will be fullscrean with status bar :)

Solution 10 - Android

@tahsinRupam answer is correct and tested on post Kitkat version.

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

If you want to use it only for a certain activity, create a style, and attach it on your manifest style like this.

<activity
    android:name=".MainActivity"
    android:screenOrientation="portrait"
    android:theme="@style/Activity.Fullscreen.Theme" />

<style name="Activity.Fullscreen.Theme" parent="MyMaterialTheme.Base">  
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

Thumbs up on origal @tahsinRupam

> Happy codings Cheers !

Solution 11 - Android

Put this code in your Activity onCreate this will hide the status bar

View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUtshawView Question on Stackoverflow
Solution 1 - AndroidVishwajit PalankarView Answer on Stackoverflow
Solution 2 - AndroidtahsinRupamView Answer on Stackoverflow
Solution 3 - AndroidPablo CegarraView Answer on Stackoverflow
Solution 4 - AndroidSanjayrajsinhView Answer on Stackoverflow
Solution 5 - AndroidMinhKhangView Answer on Stackoverflow
Solution 6 - AndroidKishan SolankiView Answer on Stackoverflow
Solution 7 - AndroidSumaniya AlabhaView Answer on Stackoverflow
Solution 8 - Androidhdk lohView Answer on Stackoverflow
Solution 9 - AndroidMostafa PirhayatiView Answer on Stackoverflow
Solution 10 - AndroidralphgabbView Answer on Stackoverflow
Solution 11 - AndroidGhanshyam SharmaView Answer on Stackoverflow