简体   繁体   English

关闭键盘后导航栏不会隐藏

[英]Navigation bar wont hide after closing keyboard

When I fill in a input field and close the keyboard my navigation bar wont hide. 当我填写输入字段并关闭键盘时,我的导航栏将不会隐藏。

Before I fill in the input field its hidden. 在我填写输入字段之前,它是隐藏的。

I tried multiple solutions but none of them work for me. 我尝试了多种解决方案,但没有一种适合我。

this.Window.AddFlags(WindowManagerFlags.Fullscreen); // hide the status bar

int uiOptions = (int)Window.DecorView.SystemUiVisibility;

uiOptions |= (int)SystemUiFlags.LowProfile;
uiOptions |= (int)SystemUiFlags.Fullscreen;
uiOptions |= (int)SystemUiFlags.HideNavigation;
uiOptions |= (int)SystemUiFlags.ImmersiveSticky;

Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;

This is the code i have in my OnCreate method in my MainActivity . 这是我MainActivity OnCreate方法中的代码。

Here is the demo. 是演示。

Implement View.IOnSystemUiVisibilityChangeListener interface: 实现View.IOnSystemUiVisibilityChangeListener接口:

    public void OnSystemUiVisibilityChange([GeneratedEnum] StatusBarVisibility visibility)
    {
        if (((int)visibility & (int)SystemUiFlags.Fullscreen) == 0)
        {
            Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
        }

    }

Add the listener for your DecorView: 为您的DecorView添加侦听器:

Window.DecorView.SetOnSystemUiVisibilityChangeListener(this);

Override OnWindowFocusChanged : 覆盖OnWindowFocusChanged

    public override void OnWindowFocusChanged(bool hasFocus)
    {
        base.OnWindowFocusChanged(hasFocus);
        Window.DecorView.SystemUiVisibility = (StatusBarVisibility)((int)SystemUiFlags.Fullscreen
            | (int)SystemUiFlags.ImmersiveSticky
            | (int)SystemUiFlags.LayoutHideNavigation
            | (int)SystemUiFlags.LayoutStable
            | (int)SystemUiFlags.HideNavigation);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM