我有一个使用新 Shell 功能的 Xamarin Forms 应用。我现在的问题是 shell 菜单区域(顶部的汉堡菜单区域)被我的应用程序覆盖,但我宁愿不被覆盖。
这就是我要说的。
您可以看到顶部带有数据和时间的区域被我的应用程序的第二张图像覆盖。我希望情况并非如此。
在其他应用程序中,我在内容页面上执行了此操作:
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS">8,20,8,0</On>
<On Platform="Android">8,0,8,0</On>
<On Platform="UWP">8,0,8,0</On>
</OnPlatform>
</ContentPage.Padding>
在 Shell 页面中我尝试过:
<Shell.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS">8,20,8,0</On>
<On Platform="Android">8,0,8,0</On>
<On Platform="UWP">8,0,8,0</On>
</OnPlatform>
</Shell.Padding>
但这没有什么区别。知道如何使日期/时间不被 Shell 菜单覆盖吗?
更新: 如下所述应用 iOS 安全区域后,该应用程序对我来说看起来是一样的:
数据和时间后面的背景仍然是 shell 标题的背景颜色(即黑色),因此您无法真正看到它们。我希望外壳向下移动,以便用户仍然可以看到左侧的日期/时间,右侧的网络/充电指示器。
最佳答案
我有一个解决方法,通过修改状态栏文本颜色来标记它。如果您的应用程序导航背景颜色始终保持深色风格,则此解决方法将没有问题。但这不是一个完美的解决方案。因为它无法在运行时修改。在找到最佳解决方案之前,您可以先尝试一下。
解决方法需要在 iOS 解决方案中打开Info.plist,
添加两个键值来修改状态栏内容的样式,
<string>Assets.xcassets/AppIcon.appiconset</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
那么即使导航栏的颜色是黑色,状态栏的文字颜色也会被看到。
第二个解决方法:(比第一个更好)
还需要在iOS解决方案中打开Info.plist,但只需在其中添加一个键值即可。
<string>Assets.xcassets/AppIcon.appiconset</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
然后在AppDelegate.cs
中添加方法将状态栏的背景颜色设置为White
颜色。
public override void OnActivated(UIApplication uiApplication)
{
base.OnActivated(uiApplication);
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
// If VS has updated to the latest version , you can use StatusBarManager , else use the first line code
// UIView statusBar = new UIView(UIApplication.SharedApplication.StatusBarFrame);
UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
statusBar.BackgroundColor = UIColor.White;
//statusBar.TintColor = UIColor.White;
UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar);
}
else
{
UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
{
statusBar.BackgroundColor = UIColor.White;
//statusBar.TintColor = UIColor.White;
UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
}
}
}
图片如下:
效果:
注意:如果稍后找到更好的解决方法,将在此处更新。
关于ios - Xamarin Forms Shell 覆盖 iOS (iPad) 上的顶级信息行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58574432/