1

I've successfully set the app in the immersive mode because I want to hide the status bar (on the top screen) and the navigation bar (on the bottom screen). The problem is that when the activity changes the bottom bar automatically arise and immediately after go down and disappear. I want to avoid this.

All activities have the style AppTheme.NoActionBar set in the manifest:

android:theme="@style/AppTheme.NoActionBar"

And in the OnCreate all have the following code:

getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() { 
                 GlobalFunctions.setFullscreen(getWindow().getDecorView());
                    }
                });

Where this is the setFullscreen() function:

public static void setFullscreen(View decorView){
        int ui_Options = 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;
        decorView.setSystemUiVisibility(ui_Options);
    }

Should I set these attributes before the onCreate in the activity lifecycle? or there are other solutions? or I've implemented the immersive mode in the wrong way?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
newUser.java
  • 197
  • 1
  • 3
  • 12

2 Answers2

1

You don't need to set the global layout listener. Just invoke the setFullscreen function before super.onCreate()

Ernest Zamelczyk
  • 2,562
  • 2
  • 18
  • 32
  • This works great but I need the GlobalLayoutListener in order to hide again the navigation bar after the keyboard is opened to write on an EditText. Maybe if I set the listener after the activity creation I can avoid that the bar appears on activity opening... – newUser.java Oct 07 '19 at 10:58
  • Solved, just added the ```setFullscreen()``` call before the ```super.onCreate()``` and no other changes. – newUser.java Oct 07 '19 at 11:11
0

Use this code in manifest activity tag

android:theme="@style/AppFullScreenTheme"

create this style in style.xml

    <style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:fontFamily">@font/montserrat</item>
    <item name="android:windowContentOverlay">@null</item>
 </style>

else use this in your activity class

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

this worked for me.

Rahul sharma
  • 1,492
  • 12
  • 26