Skip to content

Instantly share code, notes, and snippets.

@bapspatil
Last active November 6, 2017 16:59
Show Gist options
  • Save bapspatil/44aea0d58f8f87c89c004a9cfa62ed85 to your computer and use it in GitHub Desktop.
Save bapspatil/44aea0d58f8f87c89c004a9cfa62ed85 to your computer and use it in GitHub Desktop.
Load an Activity/Fragment in different Immersive modes
/*
** 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