当屏幕键盘出现在 Android 时,xamarin 表单中的隐藏导航栏会显示出来
Hidden navigation bar in xamarin forms shows up when on screen keyboard comes up on Android
对于项目,android 应用程序中的底部导航栏需要不可见。
在四处浏览时发现此代码并且它最初有效:
这是 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;
}
在点击条目时出现屏幕键盘之前,此代码一直有效。这将再次显示导航栏,并且即使在键盘被 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.
此代码将用于内部系统,重要的是用户不能在 android os 上乱搞。
关于如何解决这个问题有什么想法吗?
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.
当您点击Entry
或Picker
时,会出现这个导航栏,无法更改。但是如果keybord或者picker消失了,让navigation bar隐藏起来,就可以这样GIF实现了。
您可以像下面的代码一样在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;
}
}
如果您可以完全控制设备,它将 运行 打开。就像我的问题一样,这是一个更好的解决方案,因为它不会让导航在任何地方弹出(这可能有问题,但在某些情况下它可能正是您所需要的)
如果您有根设备,您可以使用 Android 调试桥 (adb.exe) 始终删除导航栏。这将不允许用户转到 os.
adb shell pm disable com.android.systemui
我在这个堆栈溢出上发现了这个 link(NartusTeam 的回应)
Is there a way to hide the system/navigation bar in Android ICS
对于项目,android 应用程序中的底部导航栏需要不可见。 在四处浏览时发现此代码并且它最初有效: 这是 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;
}
在点击条目时出现屏幕键盘之前,此代码一直有效。这将再次显示导航栏,并且即使在键盘被 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.
此代码将用于内部系统,重要的是用户不能在 android os 上乱搞。
关于如何解决这个问题有什么想法吗?
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.
当您点击Entry
或Picker
时,会出现这个导航栏,无法更改。但是如果keybord或者picker消失了,让navigation bar隐藏起来,就可以这样GIF实现了。
您可以像下面的代码一样在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;
}
}
如果您可以完全控制设备,它将 运行 打开。就像我的问题一样,这是一个更好的解决方案,因为它不会让导航在任何地方弹出(这可能有问题,但在某些情况下它可能正是您所需要的) 如果您有根设备,您可以使用 Android 调试桥 (adb.exe) 始终删除导航栏。这将不允许用户转到 os.
adb shell pm disable com.android.systemui
我在这个堆栈溢出上发现了这个 link(NartusTeam 的回应) Is there a way to hide the system/navigation bar in Android ICS