Android - Webview in fullscreen mode how to hide notificationbar if softkeybaord is present

本秂侑毒 提交于 2019-12-07 17:47:42

问题


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: http://imgur.com/a/cKWg8#0) 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!


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



回答2:


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


来源:https://stackoverflow.com/questions/26990661/android-webview-in-fullscreen-mode-how-to-hide-notificationbar-if-softkeybaord

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!