AdvancedImmersiveMode/Application/src/main/java/com/example/android/advancedimmersivemode/AdvancedImmersiveModeFragment.java
public void toggleUiFlags() {

        // BEGIN_INCLUDE (get_current_ui_flags)
        // The "Decor View" is the parent view of the Activity.  It's also conveniently the easiest
        // one to find from within a fragment, since there's a handy helper method to pull it, and
        // we don't have to bother with picking a view somewhere deeper in the hierarchy and calling
        // "findViewById" on it.
        View decorView = getActivity().getWindow().getDecorView();
        int uiOptions = decorView.getSystemUiVisibility();
        int newUiOptions = uiOptions;
        // END_INCLUDE (get_current_ui_flags)

        // BEGIN_INCLUDE (toggle_lowprofile_mode)
        // Low profile mode doesn't resize the screen at all, but it covers the nav & status bar
        // icons with black so they're less distracting.  Unlike "full screen" and "hide nav bar,"
        // this mode doesn't interact with immersive mode at all, but it's instructive when running
        // this sample to observe the differences in behavior.
        if (mLowProfileCheckBox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
        }
        // END_INCLUDE (toggle_lowprofile_mode)

        // BEGIN_INCLUDE (toggle_fullscreen_mode)
        // When enabled, this flag hides non-critical UI, such as the status bar,
        // which usually shows notification icons, battery life, etc
        // on phone-sized devices.  The bar reappears when the user swipes it down.  When immersive
        // mode is also enabled, the app-drawable area expands, and when the status bar is swiped
        // down, it appears semi-transparently and slides in over the app, instead of pushing it
        // down.
        if (mHideStatusBarCheckBox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
        }
        // END_INCLUDE (toggle_fullscreen_mode)

        // BEGIN_INCLUDE (toggle_hidenav_mode)
        // When enabled, this flag hides the black nav bar along the bottom,
        // where the home/back buttons are.  The nav bar normally instantly reappears
        // when the user touches the screen.  When immersive mode is also enabled, the nav bar
        // stays hidden until the user swipes it back.
        if (mHideNavCheckbox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        }
        // END_INCLUDE (toggle_hidenav_mode)

        // BEGIN_INCLUDE (toggle_immersive_mode)
        // Immersive mode doesn't do anything without at least one of the previous flags
        // enabled.  When enabled, it allows the user to swipe the status and/or nav bars
        // off-screen.  When the user swipes the bars back onto the screen, the flags are cleared
        // and immersive mode is automatically disabled.
        if (mImmersiveModeCheckBox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE;
        }
        // END_INCLUDE (toggle_immersive_mode)

        // BEGIN_INCLUDE (toggle_immersive_mode_sticky)
        // There's actually two forms of immersive mode, normal and "sticky".  Sticky immersive mode
        // is different in 2 key ways:
        //
        // * Uses semi-transparent bars for the nav and status bars
        // * This UI flag will *not* be cleared when the user interacts with the UI.
        //   When the user swipes, the bars will temporarily appear for a few seconds and then
        //   disappear again.
        if (mImmersiveModeStickyCheckBox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }
        // END_INCLUDE (toggle_immersive_mode_sticky)

        // BEGIN_INCLUDE (set_ui_flags)
        //Set the new UI flags.
        decorView.setSystemUiVisibility(newUiOptions);
        // END_INCLUDE (set_ui_flags)

        dumpFlagStateToLog(uiOptions);
    }
/**
     * Detects and toggles immersive mode (also known as "hidey bar" mode).
     */
Detects and toggles immersive mode (also known as "hidey bar" mode).
Detects and toggles immersive mode ( also known as " hidey bar " mode ) .
public void toggleUiFlags() {
        View decorView = getActivity().getWindow().getDecorView();
        int uiOptions = decorView.getSystemUiVisibility();
        int newUiOptions = uiOptions;
        if (mLowProfileCheckBox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
        }
        if (mHideStatusBarCheckBox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
        }
        if (mHideNavCheckbox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        }
        if (mImmersiveModeCheckBox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE;
        }
         * Uses semi-transparent bars for the nav and status bars
         * This UI flag will *not* be cleared when the user interacts with the UI.
           When the user swipes, the bars will temporarily appear for a few seconds and then
           disappear again.
        if (mImmersiveModeStickyCheckBox.isChecked()) {
            newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        } else {
            newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }
         END_INCLUDE (toggle_immersive_mode_sticky)
         BEGIN_INCLUDE (set_ui_flags)
        Set the new UI flags.
        decorView.setSystemUiVisibility(newUiOptions);
         END_INCLUDE (set_ui_flags)
        dumpFlagStateToLog(uiOptions);
    }
public void toggleUiFlags ( ) { View decorView = getActivity ( ) . getWindow ( ) . getDecorView ( ) ; int uiOptions = decorView . getSystemUiVisibility ( ) ; int newUiOptions = uiOptions ; if ( mLowProfileCheckBox . isChecked ( ) ) { newUiOptions |= View . SYSTEM_UI_FLAG_LOW_PROFILE ; } else { newUiOptions &= ~ View . SYSTEM_UI_FLAG_LOW_PROFILE ; } if ( mHideStatusBarCheckBox . isChecked ( ) ) { newUiOptions |= View . SYSTEM_UI_FLAG_FULLSCREEN ; } else { newUiOptions &= ~ View . SYSTEM_UI_FLAG_FULLSCREEN ; } if ( mHideNavCheckbox . isChecked ( ) ) { newUiOptions |= View . SYSTEM_UI_FLAG_HIDE_NAVIGATION ; } else { newUiOptions &= ~ View . SYSTEM_UI_FLAG_HIDE_NAVIGATION ; } if ( mImmersiveModeCheckBox . isChecked ( ) ) { newUiOptions |= View . SYSTEM_UI_FLAG_IMMERSIVE ; } else { newUiOptions &= ~ View . SYSTEM_UI_FLAG_IMMERSIVE ; } if ( mImmersiveModeStickyCheckBox . isChecked ( ) ) { newUiOptions |= View . SYSTEM_UI_FLAG_IMMERSIVE_STICKY ; } else { newUiOptions &= ~ View . SYSTEM_UI_FLAG_IMMERSIVE_STICKY ; } decorView . setSystemUiVisibility ( newUiOptions ) ; dumpFlagStateToLog ( uiOptions ) ; }
Detects and toggles immersive mode (also known as "hidey bar" mode).
Detects and toggles immersive mode ( also known as " hidey bar " mode ) .
// BEGIN_INCLUDE (get_current_ui_flags) // The "Decor View" is the parent view of the Activity.  It's also conveniently the easiest // one to find from within a fragment, since there's a handy helper method to pull it, and // we don't have to bother with picking a view somewhere deeper in the hierarchy and calling // "findViewById" on it. // END_INCLUDE (get_current_ui_flags) // BEGIN_INCLUDE (toggle_lowprofile_mode) // Low profile mode doesn't resize the screen at all, but it covers the nav & status bar // icons with black so they're less distracting.  Unlike "full screen" and "hide nav bar," // this mode doesn't interact with immersive mode at all, but it's instructive when running // this sample to observe the differences in behavior. // END_INCLUDE (toggle_lowprofile_mode) // BEGIN_INCLUDE (toggle_fullscreen_mode) // When enabled, this flag hides non-critical UI, such as the status bar, // which usually shows notification icons, battery life, etc // on phone-sized devices.  The bar reappears when the user swipes it down.  When immersive // mode is also enabled, the app-drawable area expands, and when the status bar is swiped // down, it appears semi-transparently and slides in over the app, instead of pushing it // down. // END_INCLUDE (toggle_fullscreen_mode) // BEGIN_INCLUDE (toggle_hidenav_mode) // When enabled, this flag hides the black nav bar along the bottom, // where the home/back buttons are.  The nav bar normally instantly reappears // when the user touches the screen.  When immersive mode is also enabled, the nav bar // stays hidden until the user swipes it back. // END_INCLUDE (toggle_hidenav_mode) // BEGIN_INCLUDE (toggle_immersive_mode) // Immersive mode doesn't do anything without at least one of the previous flags // enabled.  When enabled, it allows the user to swipe the status and/or nav bars // off-screen.  When the user swipes the bars back onto the screen, the flags are cleared // and immersive mode is automatically disabled. // END_INCLUDE (toggle_immersive_mode) // BEGIN_INCLUDE (toggle_immersive_mode_sticky) // There's actually two forms of immersive mode, normal and "sticky".  Sticky immersive mode // is different in 2 key ways: // // * Uses semi-transparent bars for the nav and status bars // * This UI flag will *not* be cleared when the user interacts with the UI. //   When the user swipes, the bars will temporarily appear for a few seconds and then //   disappear again. // END_INCLUDE (toggle_immersive_mode_sticky) // BEGIN_INCLUDE (set_ui_flags) //Set the new UI flags. // END_INCLUDE (set_ui_flags)