Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar with Immersive Full-Screen Mode

Is it possible to use Immersive Mode on Android KitKat and Lollipop in combination with a Toolbar?

Toolbar

 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

hide Action Bar (Toolbar)

    // This snippet hides the system bars.
    // https://developer.android.com/training/system-ui/immersive.html
private void hideSystemUI() {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.

    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);

    getSupportActionBar().hide();
}

This works fine. But the Toolbar doesn't appear again.

like image 254
momo Avatar asked Feb 27 '15 13:02

momo


People also ask

What is immersive full screen?

Immersive Mode, also known as full screen mode on Android, hides the status and navigation bars while using certain apps. Immersive Mode on Android is only enabled in certain apps by default, but there are ways to turn full screen mode on and off at will without rooting your device.

How do I get full screen instead of F11?

If you use a laptop or convertible device with an Fn key on the keyboard, you might have to press Fn + F11 instead of F11. An alternative way to get into full-screen mode in Google Chrome is to open its menu from the top-right side of the window.

How do I make the tab bar full screen?

Shift-CMD-F is for presentation mode and will hide the tabs. You want full screen mode instead, so use Control-CMD-F. Tabs will show in full screen mode.


1 Answers

Try this

 @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        if (hasFocus) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}
like image 64
Harsh Dalwadi Avatar answered Oct 15 '22 12:10

Harsh Dalwadi