简体   繁体   English

向上滑动后如何拦截android底部导航栏的可见性

[英]How to intercept android bottom navigation bar visibility after swipe up

My Xamarin.Android MVVMCross fragment implements View.IOnSystemUiVisibilityChangeListener我的 Xamarin.Android MVMCross 片段实现了 View.IOnSystemUiVisibilityChangeListener
Here is fragment OnViewCreated method这是片段OnViewCreated方法

View _decorview = ParentActivity.Window.DecorView;
_decorview.SetOnSystemUiVisibilityChangeListener(this);
var uiOptions =
                SystemUiFlags.HideNavigation |
                SystemUiFlags.ImmersiveSticky;
            _decorview.SystemUiVisibility = (StatusBarVisibility)uiOptions;

Here is an OnSystemUiVisibilityChange method:这是一个OnSystemUiVisibilityChange方法:

public void OnSystemUiVisibilityChange([GeneratedEnum] StatusBarVisibility visibility)
        {
            if (((int)visibility & (int)SystemUiFlags.HideNavigation) == 0)
            {
                if (ParentActivity.BottomNavigation != null)
                    ParentActivity.BottomNavigation.Visibility = ViewStates.Gone;
            }
            else
            {
                if (ParentActivity.BottomNavigation != null)
                    ParentActivity.BottomNavigation.Visibility = ViewStates.Visible;
            }
        }

But this method doesn't calls when I swipe up to show navigation bar但是当我向上滑动以显示导航栏时,此方法不会调用

标记SystemUiFlags.ImmersiveSticky防止在系统 UI 可见性更改时接收回调

AlexTsy.亚历克斯。

I agree that the documentation states ImmersiveSticky prevents receiving the callback.我同意文档说明 ImmersiveSticky 阻止接收回调。

However, when I moved to Android 10 I had problems with all my StickyImmersive screens on rotation.但是,当我迁移到 Android 10 时,我的所有 StickyImmersive 屏幕都在旋转时遇到了问题。 There would be spurious system bar reappearances.会出现虚假的系统栏。 Not every rotation, but rotate enough times and they would start appearing.不是每次旋转,但旋转足够多次,它们就会开始出现。 All these screens worked fine with Android 9 and lower and still do without the callback, but any Android 10 device needs the callback.所有这些屏幕在 Android 9 及更低版本上都运行良好,并且仍然没有回调,但任何 Android 10 设备都需要回调。 In desperation, I tried adding a View.IOnSystemUiVisibilityChangeListener to the fragment and that fixed it.无奈之下,我尝试向片段添加一个 View.IOnSystemUiVisibilityChangeListener 并修复了它。 The additional code didn't have any adverse effect on the devices with Android 9 or less.附加代码对搭载 Android 9 或更低版本的设备没有任何不利影响。

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

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