简体   繁体   English

xamarin forms 中的隐藏导航栏在 Android 上出现屏幕键盘时显示

[英]Hidden navigation bar in xamarin forms shows up when on screen keyboard comes up on Android

For a project the bottom navigation bar in an android app needs to be not visible.对于一个项目,android 应用程序中的底部导航栏需要不可见。 Found this code on browsing around and it works initially: This is some code in MainActivity.cs在浏览时发现了这段代码,它最初可以工作:这是 MainActivity.cs 中的一些代码

protected override void OnCreate(Bundle savedInstanceState)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(savedInstanceState);
    HideNavAndStatusBar();
    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    LoadApplication(new App());
}

private void HideNavAndStatusBar()
{
    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 code works until the on screen keyboard comes up when tapping on an entry.此代码一直有效,直到点击条目时出现屏幕键盘。 This shows the navigation bar again and it stays on even when the keyboard is closed.这将再次显示导航栏,即使键盘关闭,它也会保持打开状态。 Similarly when a picker is tapped, the navigation bar pops up as well, when the picker window is closed the navigation bar is gone again. Similarly when a picker is tapped, the navigation bar pops up as well, when the picker window is closed the navigation bar is gone again.

This code will be used for an internal system and it is very important that the user can not go and mess around on the android os.此代码将用于内部系统,非常重要的是用户不能 go 和 android 操作系统乱七八糟。

Any ideas on how to fix this?有想法该怎么解决这个吗?

This code works until the on screen keyboard comes up when tapping on an entry.此代码一直有效,直到点击条目时出现屏幕键盘。 This shows the navigation bar again and it stays on even when the keyboard is closed.这将再次显示导航栏,即使键盘关闭,它也会保持打开状态。

When you click the Entry or Picker , this navigation bar will appear, it cannot be changed.当您点击EntryPicker时,会出现此导航栏,无法更改。 But if keybord or picker is disappear, make the navigation bar is hide, it could be achieved like this GIF.但是如果keybord或者picker消失了,让导航栏隐藏起来,就可以像这个GIF那样实现。

在此处输入图像描述

You can call HideNavAndStatusBar method in SystemUiVisibilityChange event again like following code.您可以像下面的代码一样在SystemUiVisibilityChange事件中再次调用HideNavAndStatusBar方法。

  [Activity(Label = "App31", Icon = "@mipmap/icon", Theme = "@style/MainTheme",WindowSoftInputMode =SoftInput.AdjustPan, MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
            HideNavAndStatusBar();

            Window.DecorView.SystemUiVisibilityChange += DecorView_SystemUiVisibilityChange;
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);          
            LoadApplication(new App());
        }

        private void DecorView_SystemUiVisibilityChange(object sender, View.SystemUiVisibilityChangeEventArgs e)
        {

            HideNavAndStatusBar();
        }


        private void HideNavAndStatusBar()
        {
            int uiOptions = (int)Window.DecorView.SystemUiVisibility;
            uiOptions |= (int)SystemUiFlags.LowProfile;
            uiOptions |= (int)SystemUiFlags.Fullscreen;
            uiOptions |= (int)SystemUiFlags.HideNavigation;
            uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
            uiOptions |= (int)SystemUiFlags.LayoutStable;

            Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
        }
}

In case you have full control of the device it will run on.如果您完全控制它将运行的设备。 Like it was the case in my problem, then this is a better solution as it does not let the navigation pop up anywhere (which could be problematic, but in some circumstances it might be exactly what you need) If you have a rooted device you can use the Android debug bridge (adb.exe) to always remove the navigation bar.就像我的问题一样,这是一个更好的解决方案,因为它不会让导航在任何地方弹出(这可能是有问题的,但在某些情况下它可能正是您需要的)可以使用Android调试桥(adb.exe)来一直去掉导航栏。 This will disallow the user to go to the os.这将不允许用户 go 到操作系统。

adb shell pm disable com.android.systemui

I found this on this stack overflow link (the response of NartusTeam) Is there a way to hide the system/navigation bar in Android ICS我在这个堆栈溢出链接上找到了这个(NartusTeam 的响应) 有没有办法隐藏 Android ICS 中的系统/导航栏

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

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