使用键盘时的沉浸模式 [英] Immersive mode while using keyboard

查看:31
本文介绍了使用键盘时的沉浸模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Xamarin.Forms app in MainActivity.cs I set immersive sticky mode:

    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(输入框)和键盘的页面出现时,它会退出沉浸式模式并且所有系统栏都变得可见.当键盘隐藏时,所有栏保持可见.

When a page with an Entry (input box) and the keyboard comes up, it goes out of immersive mode and all system bars become visible. When keyboard is hidden, all bars stay visible.

同时使用 Acr.UserDialogsShowLoading().

如何始终保持沉浸模式?或者在关闭键盘时,以及调用UserDialogsHideLoading()时如何返回沉浸模式?

How to stay in immersive mode all the time? Or how to return to immersive mode when closing the keyboard, and when calling HideLoading() of UserDialogs?

推荐答案

我相信您正在寻找的是 IOnSystemUiVisibilityChangeListener 接口.

I believe what you're looking for is the IOnSystemUiVisibilityChangeListener interface.

创建一个监听器:

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

并将其附加到您的装饰视图:

And attach it to your decor view:

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

如果这不起作用,您可能需要探索听键盘隐藏;这里有一些研究可以帮助您入门如何捕获虚拟键盘显示/隐藏";Android 中的事件?

If this does not work you may have to explore listening for the keyboard to hide; here is some research to get you started How to capture the "virtual keyboard show/hide" event in Android?

这篇关于使用键盘时的沉浸模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆