# Immersive mode broken?

**URL:** <https://discourse.processing.org/t/immersive-mode-broken/7694>\
**Category:** Processing for Android\
**Created:** [January 21, 2019, 10:35am UTC](https://discourse.processing.org/t/immersive-mode-broken/7694 "2019-01-21T10:35:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [January 21, 2019, 10:35am UTC](https://discourse.processing.org/t/immersive-mode-broken/7694/1 "2019-01-21T10:35:45Z")

</div>

Hi

Just upgrade my phone from 7.1 to 8.1 and seem to have lost immersive mode … bottom menu bar is permanently visible, I recall that immersive was set to be default behaviour for Android mode a year or so ago  
… or maybe even longer than that… but does this need updating for the latest android versions?

Or… can some one provide a code snippet that would let me set immersive mode myself?

Many thanks

Mark

EDIT:

Just managed to get it working in Android Studio by pasting the code below into the Main Activity, but how can I get it to work in Processing? The errors I get are

```auto
1. ERROR in C:\Users\MArk\AppData\Local\Temp\android4180019193616482448sketch\app\src\main\java\com\softwarecreative\sessionsheddemo\SessionShed.java (at line 751)
	public void onWindowFocusChanged(boolean hasFocus) {
	            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The method onWindowFocusChanged(boolean) of type SessionShed must override or implement a supertype method
----------
2. ERROR in C:\Users\MArk\AppData\Local\Temp\android4180019193616482448sketch\app\src\main\java\com\softwarecreative\sessionsheddemo\SessionShed.java (at line 752)
	super.onWindowFocusChanged(hasFocus);
	      ^^^^^^^^^^^^^^^^^^^^
The method onWindowFocusChanged(boolean) is undefined for the type PApplet
----------
2 problems (2 errors)

```

```auto

 @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        hideSystemUI();
    }
}

private void 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
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            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.
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            // Hide the nav bar and status bar
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | 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 void showSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

```

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 21, 2019, 6:41pm UTC](https://discourse.processing.org/t/immersive-mode-broken/7694/2 "2019-01-21T18:41:56Z")

</div>

@shedMusic ===  
the error (with P5) is probably (i have to get a look at that to morrow) because you are in a fragment and not in an activity…

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [January 22, 2019, 7:53am UTC](https://discourse.processing.org/t/immersive-mode-broken/7694/3 "2019-01-22T07:53:59Z")

</div>

@akenaton thanks for replying …

maybe … but it was already a fragment for me (has been for a long time)… changing OS from 7.1 to 8.1 made the difference? Immersive mode was default behaviour for Android Mode but now seems broken. No worries though as I tend to port my sketches to AS now for finishing, as I can generate my apks with existing keys etc, and it was easy to get the immersive mode working there.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 22, 2019, 7:58am UTC](https://discourse.processing.org/t/immersive-mode-broken/7694/4 "2019-01-22T07:58:23Z")

</div>

@shedMusic ===  
i was only speaking about the 2 error code, not about the immersive mode…

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [January 22, 2019, 8:01am UTC](https://discourse.processing.org/t/immersive-mode-broken/7694/5 "2019-01-22T08:01:37Z")

</div>

@akenaton

OK I understand. Thanks

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [January 22, 2019, 9:56am UTC](https://discourse.processing.org/t/immersive-mode-broken/7694/6 "2019-01-22T09:56:55Z")

</div>

@shedMusic===

try this code (some modifs for fragment); of course it could be useful (for testing) to add somme toggle button with a listener for calling the other method( show…)…

```auto
import android.view.View;
void setup(){
  size(800,1000);
}

void draw(){
  
}
 //@Override
public void onWindowFocusChanged(boolean hasFocus) {
   this.getActivity().onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        hideSystemUI();
    }
}

private void 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
    View decorView = getActivity().getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            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.
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            // Hide the nav bar and status bar
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | 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 void showSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

```

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [January 22, 2019, 11:05am UTC](https://discourse.processing.org/t/immersive-mode-broken/7694/7 "2019-01-22T11:05:47Z")

</div>

@akenaton  
Thanks … will give that a try 🙂

---

<div class="post-metadata">

**Author:** ![shedMusic](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/shedmusic/32/601_2.png) [@shedMusic](https://discourse.processing.org/u/shedMusic)\
**Post date:** [January 22, 2019, 9:27pm UTC](https://discourse.processing.org/t/immersive-mode-broken/7694/8 "2019-01-22T21:27:02Z")

</div>

@akenaton  
Yes that worked fine  
Many thanks 🙂
