3

I have developed a small Android app using a webview. All Android UI elements such as notificationbar, statusbar, actionbar are hidden using:

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

}

If I open an HTML formular and tap into one input field, the softkeyboard shows up. But then also the Android notificationbar appears, what I don't want. (see images: https://i.stack.imgur.com/RnCtD.jpg) If I close the softkeyboard by the upper left key on the softkeyboard, the notificationbar still remains open and occupies a part of my title bar on my HTML page. How can I hide the notificationbar if softkeyboard is opened?

Thanks!

mr.burns
  • 493
  • 2
  • 6
  • 14

2 Answers2

1

This works for me. Call this in onCreate:

private void setupFullscreenMode() {
    View decorView = setFullscreen();
    decorView
            .setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
                @Override
                public void onSystemUiVisibilityChange(int visibility) {
                    setFullscreen();
                }
            });
}

private View setFullscreen() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    return decorView;
}

Also override onWindowsFocusChanged:

public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        setFullscreen();
    }
}
Magnus G
  • 111
  • 4
  • The code does work for webview's input because of the soft keyboard is shown with the navigation bar. Check http://stackoverflow.com/a/28060917/1030870 for a workaround solution. – Mine Jan 21 '15 at 06:38
0

I had the same problem, solved it by doing this:

    mWebView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            hideSystemUI(); // setup fullscreen
        }
    });
Berťák
  • 7,143
  • 2
  • 29
  • 38