使用键盘时的沉浸式模式

时间:2018-05-28 12:26:42

标签: xamarin.forms xamarin.android

MainActivity.cs中的Xamarin.Forms应用程序中,我设置了沉浸式粘性模式:

    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        base.OnCreate(bundle);
        Xamarin.Forms.Forms.Init(this, bundle);
        SetFullscreen();
        LoadApplication(new App());
    }

    void SetFullscreen()
    {
        var 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;
        Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
    }

当带有Entry(输入框)和键盘的页面出现时,它会退出沉浸式模式,并且所有系统栏都会变得可见。当隐藏键盘时,所有条形都可见。

同时将Acr.UserDialogsShowLoading()一起使用。

如何始终保持沉浸式模式?或者在关闭键盘时以及在调用HideLoading()的{​​{1}}时如何返回沉浸式模式?

1 个答案:

答案 0 :(得分:1)

我相信你要找的是IOnSystemUiVisibilityChangeListener界面。

创建一个你的监听器:

class SystemUiVisibilityChangeListener : Java.Lang.Object, View.IOnSystemUiVisibilityChangeListener
    {
        public void OnSystemUiVisibilityChange([GeneratedEnum] StatusBarVisibility visibility)
        {
            if (visibility == StatusBarVisibility.Visible)
            {
                //your code here
            }
        }
    }

并将其附在您的装饰视图中:

View decorView = Window.DecorView;
decorView.SetOnSystemUiVisibilityChangeListener(new SystemUiVisibilityChangeListener());
var uiOptions = (int)decorView.SystemUiVisibility;
...

如果这不起作用,您可能需要探索聆听键盘隐藏;这里有一些让你入门的研究How to capture the "virtual keyboard show/hide" event in Android?