gpt4 book ai didi

xamarin - 当屏幕键盘出现在 Android 上时,xamarin 表单中的隐藏导航栏会出现

转载 作者:行者123 更新时间:2023-12-05 07:06:37 25 4
gpt4 key购买 nike

对于项目,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;
}

此代码一直有效,直到在点击条目时出现屏幕键盘。这将再次显示导航栏,即使键盘关闭,它也会保持打开状态。同样,当采集器被挖掘时,导航栏也会弹出,当接线器窗口关闭时,导航栏再次消失。

此代码将用于内部系统,用户不能在 android 操作系统上乱搞是非常重要的。

关于如何解决这个问题有什么想法吗?

最佳答案

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.

当您点击EntryPicker时,会出现这个导航栏,无法更改。但是如果keybord或者picker消失了,让navigation bar隐藏起来,就可以像这个GIF那样实现。

enter image description here

您可以像下面的代码一样在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;
}
}

关于xamarin - 当屏幕键盘出现在 Android 上时,xamarin 表单中的隐藏导航栏会出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62404096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com