Android - webview full screen, how to hide notification bar if softkeybaord is present

I have developed a small android app using webview. All Android interface elements like notification bar, status bar, action bar are hidden with:

  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 form and select one input field, the on-screen keyboard appears. But then the Android notification bar appears, which is not what I want. (see images: http://imgur.com/a/cKWg8#0 ) If I close the soft keyboard with the left key on my keyboard, the notification bar is still open and takes up part of my title bar on my HTML page. How do I hide the notification panel when the software keyboard is open?

Thank!

+3


source to share


2 answers


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

      

+1


source


I had the same problem solving it by doing the following:



    mWebView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            hideSystemUI(); // setup fullscreen
        }
    });

      

0


source







All Articles