Immersive Mode not working after onWindowFocusChanged()
See original GitHub issueIn AndroidApplication.java:
protected void hideStatusBar (boolean hide) {
if (!hide || getVersion() < 11) return;
View rootView = getWindow().getDecorView();
try {
Method m = View.class.getMethod("setSystemUiVisibility", int.class);
if (getVersion() <= 13) m.invoke(rootView, 0x0);
m.invoke(rootView, 0x1);
} catch (Exception e) {
log("AndroidApplication", "Can't hide status bar", e);
}
}
@Override
public void onWindowFocusChanged (boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
useImmersiveMode(this.useImmersiveMode);
hideStatusBar(this.hideStatusBar);
if (hasFocus) {
this.wasFocusChanged = 1;
if (this.isWaitingForAudio) {
this.audio.resume();
this.isWaitingForAudio = false;
}
} else {
this.wasFocusChanged = 0;
}
}
@TargetApi(19)
@Override
public void useImmersiveMode (boolean use) {
if (!use || getVersion() < Build.VERSION_CODES.KITKAT) return;
View view = getWindow().getDecorView();
try {
Method m = View.class.getMethod("setSystemUiVisibility", int.class);
int code = 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;
m.invoke(view, code);
} catch (Exception e) {
log("AndroidApplication", "Can't set immersive mode", e);
}
}
Method onWindowFocusChanged() contains a bug, useImmersiveMode() should be executed after hideStatusBar() and not before. As it is now, hideStatusBar() overwrites the changes to SystemUiVisibility done by useImmersiveMode(), and this makes Immersive Mode not working after a call to onWindowFocusChanged()
Issue Analytics
- State:
- Created 8 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
Return to immersive mode after closing the keyboard on Android
I used handlers to detect user inactivity and hide system ui thereafter. It automatically detect if user is not interacting on screen then...
Read more >Moving forward with the example | Mastering Android Game ...
Immersive mode hides the Status and Navigation bars completely. It is designed, as the name indicates, for fully-immersive experiences, which means games mostly ......
Read more >Activity - Android Developers
onRestart(), Called after your activity has been stopped, prior to it being started again. ... Adjust the current immersive mode setting.
Read more >Android Immersive fullscreen mode - Qt Forum
I have this class in my app and tried doing this. The method onWindowFocusChanged() was not called. Here I found solution with QtActivity.java ......
Read more >react-native-immersive - npm
Start using react-native-immersive in your project by running `npm ... and Immersive Full-Screen Mode is first introduced since Android 4.4 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I struggled a while with this immersive mode, which was working randomly, especially on slow devices. I discovered this stackoverflow answer which refers to a google sample The
setSystemUiVisibility
call should be manager by a handler and delayed by 300ms. Also I thinkhideStatusBar()
anduseImmersive()
calls should be merged in a singlesetSystemUiVisibility()
call, because otherwise, on focus change, the status bar gets shown for a very short time (which causes a very unpleasant blink effect). I finally setconfig.hideStatusBar
tofalse
.It works for me. If no one has a complaint, can we close this, please?