Last active
November 6, 2017 16:59
-
-
Save bapspatil/44aea0d58f8f87c89c004a9cfa62ed85 to your computer and use it in GitHub Desktop.
Load an Activity/Fragment in different Immersive modes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** Created by bapspatil | |
*/ | |
private void immersiveMode() { | |
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); | |
} | |
private void stickyImmersiveMode() { | |
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 | |
| View.SYSTEM_UI_FLAG_FULLSCREEN | |
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); | |
} | |
// Override the onWindowFocusChanged() method in the Activity/Fragment to change the mode if the orientation changes, most commonly used in YouTube app when you use it in landscape | |
@Override | |
public void onWindowFocusChanged(boolean hasFocus) { | |
super.onWindowFocusChanged(hasFocus); | |
if (hasFocus) { | |
stickyImmersiveMode(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment