Fullscreen Activity in Android?

AndroidAndroid ActivityFullscreenAndroid Fullscreen

Android Problem Overview


How do I make an activity full screen? Without the notification bar.

Android Solutions


Solution 1 - Android

You can do it programatically:

public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

Or you can do it via your AndroidManifest.xml file:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

Edit:

If you are using AppCompatActivity then you need to add new theme

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

and then use it.

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"/>

Thanks to https://stackoverflow.com/a/25365193/1646479

Solution 2 - Android

There's a technique called Immersive Full-Screen Mode available in KitKat. Immersive Full-Screen Mode Demo

Example

Solution 3 - Android

If you don't want to use the theme @android:style/Theme.NoTitleBar.Fullscreen because you are already using a theme of you own, you can use android:windowFullscreen.

In AndroidManifest.xml:

<activity
  android:name=".ui.activity.MyActivity"
  android:theme="@style/MyTheme">
</activity>

In styles.xml:

<style name="MyTheme"  parent="your parent theme">
  <item name="android:windowNoTitle">true</item>
  <item name="android:windowFullscreen">true</item> 
</style>

Solution 4 - Android

In AndroidManifest.xml file:

<activity
    android:name=".Launch"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <!-- This line is important -->

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>  

Or in Java code:

protected void onCreate(Bundle savedInstanceState){
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

Solution 5 - Android

If your using AppCompat and ActionBarActivity, then use this

getSupportActionBar().hide();

Solution 6 - Android

Be careful with

requestWindowFeature(Window.FEATURE_NO_TITLE);

If you are using any method to set the action bar as the follow:

getSupportActionBar().setHomeButtonEnabled(true);

It will cause a null pointer exception.

Solution 7 - Android

Try this with appcompat from style.xml. It provides support for all platforms.

<!-- Application theme. -->
<style name="AppTheme.FullScreen" parent="AppTheme">
    <item name="android:windowFullscreen">true</item>
</style>


<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />

Solution 8 - Android

For Androidx

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 9 - Android

Using Android Studio (current version is 2.2.2 at moment) is very easy to add a fullscreen activity.

See the steps:

  1. Right click on your java main package > Select “New” > Select “Activity” > Then, click on “Fullscreen Activity”.

Step one

  1. Customize the activity (“Activity Name”, “Layout Name” and so on) and click “finish”.

Step two

Done!

Now you have a fullscreen activity made easily (see the java class and the activity layout to know how the things works)!

Solution 10 - Android

First you must to set you app theme with "NoActionBar" like below

<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />

Then add these lines in your fullscreen activity.

public class MainActiviy extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

It will hide actionbar/toolbar and also statusbar in your fullscreen activity

Solution 11 - Android

For those using AppCompact... style.xml

 <style name="Xlogo" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

Then put the name in your manifest...

Solution 12 - Android

AndroidManifest.xml

<activity ...
          android:theme="@style/FullScreenTheme"
    >
</activity>

I. Your main app the theme is Theme.AppCompat.Light.DarkActionBar

For hide ActionBar / StatusBar
style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
</style>

<style name="FullScreenTheme" parent="AppTheme">
    <!--this property will help hide the ActionBar-->
    <item name="windowNoTitle">true</item>
    <!--currently, I don't know why we need this property since use windowNoTitle only already help hide actionbar. I use it because it is used inside Theme.AppCompat.Light.NoActionBar (you can check Theme.AppCompat.Light.NoActionBar code). I think there are some missing case that I don't know-->
    <item name="windowActionBar">false</item>
    <!--this property is used for hiding StatusBar-->
    <item name="android:windowFullscreen">true</item>
</style>

To hide the system navigation bar

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        setContentView(R.layout.activity_main)
        ...
    }
 }

II. Your main app theme is Theme.AppCompat.Light.NoActionBar

For hide ActionBar / StatusBar
style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
</style>

<style name="FullScreenTheme" parent="AppTheme">
    <!--don't need any config for hide ActionBar because our apptheme is NoActionBar-->
    <!--this property is use for hide StatusBar-->
    <item name="android:windowFullscreen">true</item> // 
</style>

To hide the system navigation bar

Similar like Theme.AppCompat.Light.DarkActionBar.

Demo

Solution 13 - Android

thanks for answer @Cristian i was getting error

> android.util.AndroidRuntimeException: requestFeature() must be called > before adding content

i solved this using

@Override
protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    super.onCreate(savedInstanceState);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_login);

    -----
    -----
}

Solution 14 - Android

Add this in styles.xml

<item name="android:windowFullscreen">true</item>

Example -

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

And change AndroidManifest file with bellow code

android:theme="@style/AppTheme"

Example -

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">

Solution 15 - Android

show Full Immersive:

private void askForFullScreen()
    {
        getActivity().getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                        | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                        | View.SYSTEM_UI_FLAG_IMMERSIVE);
    }

move out of full immersive mode:

 private void moveOutOfFullScreen() {
        getActivity().getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }

Solution 16 - Android

Here is an example code. You can turn on/off flags to hide/show specific parts.

enter image description here

public static void hideSystemUI(Activity activity) {
    View decorView = activity.getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    //| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    //| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                    | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

Then, you reset to the default state:

enter image description here

public static void showSystemUI(Activity activity) {
    View decorView = activity.getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

You can call the above functions from your onCreate:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.course_activity);
    UiUtils.hideSystemUI(this);
}

Solution 17 - Android

I wanted to use my own theme instead of using @android:style/Theme.NoTitleBar.Fullscreen. But it wasn't working as some post on here had mentioned, so I did some tweaking to figure it out.

In AndroidManifest.xml:

<activity
    android:name=".ui.activity.MyActivity"
    android:theme="@style/MyTheme">
</activity>

In styles.xml:

<style name="MyTheme">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
</style>

Note: in my case I had to use name="windowActionBar" instead of name="android:windowActionBar" before it worked properly. So I just used both to make sure in the case I need to port to a new Android version later.

Solution 18 - Android

KOTLIN

Following the google doc, there is a easy way :

override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) hideSystemUI() }


private fun hideSystemUI() {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
        // Set the content to appear under the system bars so that the
        // content doesn't resize when the system bars hide and show.
        or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        // Hide the nav bar and status bar
        or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_FULLSCREEN)      }


// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private fun showSystemUI() {
window.decorView.systemUiVisibility = 
(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)       }

Google docs

Solution 19 - Android

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:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

  1. If you want to remove the toolbar from only one activity then go to manifest, under activity tag add this: 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()

Solution 20 - Android

TIP: Using getWindow().setLayout() can screw up your full screen display! Note the documentation for this method says:

> Set the width and height layout parameters of the window... > you can change them to ... an absolute value to make a window that is not full-screen.

http://developer.android.com/reference/android/view/Window.html#setLayout%28int,%20int%29

For my purposes, I found that I had to use setLayout with absolute parameters to resize my full screen window correctly. Most of the time, this worked fine. It was called by an onConfigurationChanged() event. There was a hiccup, however. If the user exited the app, changed the orientation, and reentered, it would lead to firing off my code which included setLayout(). During this re-entry time window, my status bar (which was hidden by the manifest) would be made to re-appear, but at any other time setLayout() would not cause this! The solution was to add an additional setLayout() call after the one with the hard values like so:

       public static void setSize( final int width, final int height ){
//DO SOME OTHER STUFF...
            instance_.getWindow().setLayout( width, height );
            // Prevent status bar re-appearance
            Handler delay = new Handler();
            delay.postDelayed( new Runnable(){ public void run() {
                instance_.getWindow().setLayout(
                    WindowManager.LayoutParams.FILL_PARENT,
                    WindowManager.LayoutParams.FILL_PARENT );
            }}, FILL_PARENT_ON_RESIZE_DELAY_MILLIS );
        }

The window then correctly re-sized, and the status bar did not re-appear regardless of the event which triggered this.

Solution 21 - Android

It worked for me.

if (Build.VERSION.SDK_INT < 16) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }

Solution 22 - Android

https://developer.android.com/training/system-ui/immersive.html

Activity :

@Override
public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}

AndroidManifests:

 <activity android:name=".LoginActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_login"
            android:theme="@style/FullscreenTheme"
            ></activity>

Solution 23 - Android

 @Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    adjustFullScreen(newConfig);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        adjustFullScreen(getResources().getConfiguration());
    }
}
private void adjustFullScreen(Configuration config) {
    final View decorView = getWindow().getDecorView();
    if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    } else {
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    }
}

Solution 24 - Android

Inside styles.xml...

<!-- No action bar -->
<style name="NoActonBar" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Theme customization. -->
    <item name="colorPrimary">#000</item>
    <item name="colorPrimaryDark">#444</item>
    <item name="colorAccent">#999</item>
    <item name="android:windowFullscreen">true</item>
</style>

This worked for me. Hope it'll help you.

Solution 25 - Android

With kotlin this is the way I did:

class LoginActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
        window.decorView.systemUiVisibility =
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
                View.SYSTEM_UI_FLAG_FULLSCREEN

    }
}

Immersive Mode

The immersive mode is intended for apps in which the user will be heavily interacting with the screen. Examples are games, viewing images in a gallery, or reading paginated content, like a book or slides in a presentation. For this, just add this lines:

View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Sticky immersive

In the regular immersive mode, any time a user swipes from an edge, the system takes care of revealing the system bars—your app won't even be aware that the gesture occurred. So if the user might actually need to swipe from the edge of the screen as part of the primary app experience—such as when playing a game that requires lots of swiping or using a drawing app—you should instead enable the "sticky" immersive mode.

View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY

For more information: Enable fullscreen mode

In case your using the keyboard, sometimes happens that StatusBar shows when keyboard shows up. In that case I usually add this to my style xml

styles.xml

<style name="FullScreen" parent="AppTheme">
    <item name="android:windowFullscreen">true</item>
</style>

And also this line to my manifest

<activity
        android:name=".ui.login.LoginActivity"
        android:label="@string/title_activity_login"
        android:theme="@style/FullScreen">

Solution 26 - Android

Just paste this code into onCreate() method

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

Solution 27 - Android

Use this method after setContentView in onCreate() and pass the Window object by getWindow().

    public void makeActivityFullScreen(Window window){
    View decorView = window.getDecorView();
    //        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
       window.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
    }
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    );
}

This code will work for notch screen also. To check the notch fullscreen you require android P but if You have a notch display phone then go to setting-->Display setting -->app display ratio --->select your app --->there will be two options safe are display and full screen , please select the full screen and run the app, you can see the fullscreen in notch also without having android Pie

Solution 28 - Android

enter image description here

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); if (getSupportActionBar() != null){ getSupportActionBar().hide(); }

Solution 29 - Android

 protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_splash_screen);
    getSupportActionBar().hide();
    
}

Solution 30 - Android

After a lot of time with no success I came with my own solution which is quit similar with another developer. So If somebody needs her it is.My problem was that system navigation bar was not hiding after calling. Also in my case I needed landscape, so just in case comment that line and that all. First of all create style

    <style name="FullscreenTheme" parent="AppTheme">
    <item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowBackground">@null</item>
    <item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
    <item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>

This is my manifest file

<activity
        android:name=".Splash"
        android:screenOrientation="landscape"
        android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|screenSize"
        android:label="@string/app_name"
        android:theme="@style/SplashTheme">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|screenSize"
        android:screenOrientation="landscape"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme">
    </activity>

This is my spalsh activity

public class Splash extends Activity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 2000;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.splash_creen);

    /* New Handler to start the Menu-Activity
     * and close this Splash-Screen after some seconds.*/
    new Handler().postDelayed(new Runnable(){
        @Override
        public void run() {
            /* Create an Intent that will start the Menu-Activity. */
            Intent mainIntent = new Intent(Splash.this,MainActivity.class);
            Splash.this.startActivity(mainIntent);
            Splash.this.finish();
        }
    }, SPLASH_DISPLAY_LENGTH);
}

}

And this is my main full screen activity. onSystemUiVisibilityChange thi method is quit important otherwise android main navigation bar after calling will stay and not disappear anymore. Really irritating problem, but this function solves that problem.

public class MainActivity extends AppCompatActivity {

private View mContentView;
@Override
public void onResume(){
    super.onResume();
    
    mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fullscreen2);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null)
    {
        actionBar.hide();
    }
    mContentView = findViewById(R.id.fullscreen_content_text);
    mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);



    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener
            (new View.OnSystemUiVisibilityChangeListener()
            {
                @Override
                public void onSystemUiVisibilityChange(int visibility)
                {
                    System.out.println("print");

                    if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
                    {
                        mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                                | View.SYSTEM_UI_FLAG_FULLSCREEN
                                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
                    }
                    else
                    {

                        mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

                        }
                }
            });

}

}

This is my splash screen layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView android:id="@+id/splashscreen" android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="@android:color/white"
        android:src="@drawable/splash"
        android:layout_gravity="center"/>
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hello World, splash"/>
</LinearLayout>

This is my fullscreen layout
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#0099cc"
        >
        <TextView
            android:id="@+id/fullscreen_content_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:keepScreenOn="true"
            android:text="@string/dummy_content2"
            android:textColor="#33b5e5"
            android:textSize="50sp"
            android:textStyle="bold" />
    
    </FrameLayout>

I hope this will help you

Solution 31 - Android

Create an empty activity and add two lines in onCreate.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // full screen activity
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getSupportActionBar().hide();

        setContentView(R.layout.activity_main);
    }
    ...
}

Solution 32 - Android

To display content through the notch or the cutout area. This can help from the docs:

> LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES - Content renders into the cutout area in both portrait and landscape modes.

Key thing for me was this line in the activity style:

// Important to draw through the cutouts
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> 

For me, I wanted to show an image in immersive mode. When I click it, I want the system UI (status & navigation bars) to show up.

Here is my solution:

1- In the Activity, some methods to show/hide system UI (status/nav bars)

private fun hideSystemUI() {
    sysUIHidden = true
    window.decorView.systemUiVisibility = (
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            or View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
            // Hide the nav bar and status bar
            or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // Hide nav bar
            or View.SYSTEM_UI_FLAG_FULLSCREEN // Hide status bar
            )
}


private fun showSystemUI() {
    sysUIHidden = false
    window.decorView.systemUiVisibility = (
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            // Set the content to appear under the system bars so that the
            // content doesn't resize when the system bars hide and show.
            or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // layout Behind nav bar
            or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // layout Behind status bar
            )
}

2- Make sure this in the root view of your xml layout

android:fitsSystemWindows="false"

3- Style for Full screen Activity will give status/navigation bars a semi transparent background when they show up:

<style name="FullscreenTheme" parent="AppTheme">
    <item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowBackground">@null</item>
    <item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
    <item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
    <item name="android:statusBarColor">#50000000</item>
    <item name="android:navigationBarColor">#50000000</item>
    // Important to draw behind cutouts
    <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> 
</style>

<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
    <item name="android:background">@color/sysTransparent</item>
</style>

Solution 33 - Android

import androidx.core.view.WindowInsetsCompat.Type

fun Activity.fullscreen() {
    with(WindowInsetsControllerCompat(window, window.decorView)) {
        systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPE
        hide(Type.systemBars())
    }
}

fun Activity.exitFullscreen() {
    WindowInsetsControllerCompat(window, window.decorView).show(Type.systemBars())
}

Solution 34 - Android

On Android 10, none worked for me.

But I that worked perfectly fine (1st line in oncreate):

    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE;
    decorView.setSystemUiVisibility(uiOptions);

    setContentView(....);

    if (getSupportActionBar() != null) {
        getSupportActionBar().hide();
    }

enjoy :)

Solution 35 - Android

Found solution from mozilla, they made an extension library here

In case link breakes here is the code


/**
 * Retrieves a {@link WindowInsetsControllerCompat} for the top-level window decor view.
 */
fun Window.getWindowInsetsController(): WindowInsetsControllerCompat {
    return WindowInsetsControllerCompat(this, this.decorView)
}


/**
 * Attempts to call immersive mode using the View to hide the status bar and navigation buttons.
 * @param onWindowFocusChangeListener optional callback to ensure immersive mode is stable
 * Note that the callback reference should be kept by the caller and be used for [exitImmersiveModeIfNeeded] call.
 */
fun Activity.enterToImmersiveMode(
    onWindowFocusChangeListener: ViewTreeObserver.OnWindowFocusChangeListener? = null
) {
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
    window.getWindowInsetsController().apply {
        hide(WindowInsetsCompat.Type.systemBars())
        systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
    }

    // We need to make sure system bars do not become permanently visible after interactions with content
    // see https://github.com/mozilla-mobile/fenix/issues/20240
    onWindowFocusChangeListener?.let {
        window.decorView.viewTreeObserver?.addOnWindowFocusChangeListener(it)
    }
}

/**
 * Attempts to come out from immersive mode using the View.
 * @param onWindowFocusChangeListener optional callback to ensure immersive mode is stable
 * Note that the callback reference should be kept by the caller and be the same used for [enterToImmersiveMode] call.
 */
@Suppress("DEPRECATION")
fun Activity.exitImmersiveModeIfNeeded(
    onWindowFocusChangeListener: ViewTreeObserver.OnWindowFocusChangeListener? = null
) {
    if (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON and window.attributes.flags == 0) {
        // We left immersive mode already.
        return
    }
    onWindowFocusChangeListener?.let {
        window.decorView.viewTreeObserver?.removeOnWindowFocusChangeListener(it)
    }
    window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
    window.getWindowInsetsController().apply {
        show(WindowInsetsCompat.Type.systemBars())
    }
}

Solution 36 - Android

Most of these answers seem to be outdated. developer.android.com recommends to do it like this:

Kotlin:

private fun hideSystemBars() {
    val windowInsetsController = ViewCompat.getWindowInsetsController(window.decorView) ?: return
    windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
    windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
}

Java:

private void hideSystemBars() {
    WindowInsetsControllerCompat windowInsetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
    if (windowInsetsController == null) {
        return;
    }
    windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
    windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
}

More info: https://developer.android.com/training/system-ui/immersive

Solution 37 - Android

According to Android developer training

You should do the following:

Kotlin:

private fun hideSystemBars() {
  val windowInsetsController =
      ViewCompat.getWindowInsetsController(window.decorView) ?: return
  // Configure the behavior of the hidden system bars
  windowInsetsController.systemBarsBehavior =
      WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
  // Hide both the status bar and the navigation bar
  windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
}

Java:

private void hideSystemBars() {
  WindowInsetsControllerCompat windowInsetsController =
      ViewCompat.getWindowInsetsController(getWindow().getDecorView());
  if (windowInsetsController == null) {
    return;
  }
  // Configure the behavior of the hidden system bars
  windowInsetsController.setSystemBarsBehavior(
      WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
  );
  // Hide both the status bar and the navigation bar
  windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
}

Solution 38 - Android

getWindow().addFlags(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

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
QuestionPraveenView Question on Stackoverflow
Solution 1 - AndroidCristianView Answer on Stackoverflow
Solution 2 - AndroidDmideView Answer on Stackoverflow
Solution 3 - AndroidAriel CabibView Answer on Stackoverflow
Solution 4 - AndroidiNFInite PosSibiLitiEsView Answer on Stackoverflow
Solution 5 - AndroidBala VishnuView Answer on Stackoverflow
Solution 6 - AndroidjiahaoView Answer on Stackoverflow
Solution 7 - AndroidRohit SutharView Answer on Stackoverflow
Solution 8 - AndroidSanjayrajsinhView Answer on Stackoverflow
Solution 9 - AndroidFilipe BritoView Answer on Stackoverflow
Solution 10 - AndroidRajesh PeramView Answer on Stackoverflow
Solution 11 - AndroidX-Black...View Answer on Stackoverflow
Solution 12 - AndroidLinhView Answer on Stackoverflow
Solution 13 - AndroidBikesh MView Answer on Stackoverflow
Solution 14 - AndroidDinithView Answer on Stackoverflow
Solution 15 - AndroidGal RomView Answer on Stackoverflow
Solution 16 - AndroidarsentView Answer on Stackoverflow
Solution 17 - AndroidChef PharaohView Answer on Stackoverflow
Solution 18 - AndroidÁlvaro AgüeroView Answer on Stackoverflow
Solution 19 - AndroidSuraj VaishnavView Answer on Stackoverflow
Solution 20 - AndroidBuvinJView Answer on Stackoverflow
Solution 21 - AndroidSinghView Answer on Stackoverflow
Solution 22 - AndroidDheerendra MitmView Answer on Stackoverflow
Solution 23 - AndroidTarun kondaView Answer on Stackoverflow
Solution 24 - AndroidAnuj SainView Answer on Stackoverflow
Solution 25 - AndroidJorge CasariegoView Answer on Stackoverflow
Solution 26 - AndroidAhsanView Answer on Stackoverflow
Solution 27 - AndroidMinionView Answer on Stackoverflow
Solution 28 - AndroidUTTAMView Answer on Stackoverflow
Solution 29 - Androidsaigopi.meView Answer on Stackoverflow
Solution 30 - AndroidJevgenij KononovView Answer on Stackoverflow
Solution 31 - AndroidwannikView Answer on Stackoverflow
Solution 32 - AndroidfullmoonView Answer on Stackoverflow
Solution 33 - AndroidTatsuya FujisakiView Answer on Stackoverflow
Solution 34 - AndroidArnaudView Answer on Stackoverflow
Solution 35 - AndroidGeorge ShalvashviliView Answer on Stackoverflow
Solution 36 - Androidnh7View Answer on Stackoverflow
Solution 37 - AndroidHasan Mhd AminView Answer on Stackoverflow
Solution 38 - AndroidShyamView Answer on Stackoverflow