1

In my android app I hide soft keys bar using this:

View decorView = getWindow().getDecorView();

int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

decorView.setSystemUiVisibility(uiOptions);

But the problem is when some message box or toast display then softkeys display again. I want to hide soft keys when any message box or toast displaying.

Is it possible.. how can i do this.

hareesh J
  • 520
  • 1
  • 6
  • 21
Trilok
  • 53
  • 1
  • 6

1 Answers1

1

Messages like dialogs, intent chooser, soft keyboard and toasts use a different Window than your main application window.
These extra Windows can change your SystemUiVisibility and Window flags as they appear and disappear.

What I found to work in most cases is to setup your flags in onWindowFocusChanged in the Activity class:

public void onWindowFocusChanged(boolean hasFocus) {
    if(hasFocus) {
        View decorView = getWindow().getDecorView();

        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

        decorView.setSystemUiVisibility(uiOptions);
    }
}

You then no longer need this code in onCreate, as window focus is also gained at activity creation.

RobCo
  • 6,240
  • 2
  • 19
  • 26
  • your solution is perfect. but the problem is I used this on video recording then displaying and hiding soft keys effect to the recorded video. – Trilok Jul 20 '17 at 11:44
  • Working with these flags is always be a bit tricky. If it doesn't work as expected its usually because of window changes (the MediaController for videoview is also in a separate window). I'm not sure about your current troubles, but I would make a `setFullscreen(boolean)` method that sets the correct flags, then try calling that in all thinkable, possibly correct, places. – RobCo Jul 20 '17 at 11:51