android - ContentPage 上方和下方的移动应用程序的背景颜色是白色而不是黑色
问题描述
我有一个适用于 mac 跨平台 Xamarin Forms 4 应用程序的 VS2019。我使用基本模板来创建它。
在我的 App.xaml.cs 文件中,我只是将 MainPage 设置为我的 ContentPage 对象。
此内容页面的背景颜色设置为黑色。
当我在我的 iPhone 上运行它时,我得到以下结果。请注意屏幕的顶部和底部都是如何具有白色背景的。我似乎无法弄清楚那是从哪里来的。
我尝试将我的内容页面包装在 NavigationPage 中并将其背景设置为黑色,但所有这些都会在我的内容页面顶部添加一点黑色并将页面的其余部分向下移动。
我无法弄清楚我的内容页面顶部和底部的背景颜色是在哪里设置的。
有人可以告诉我吗?
更新:在评论中添加了一些要求的内容:
应用程序.xaml:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="UpdateAgent.App">
<Application.Resources>
</Application.Resources>
</Application>
应用程序.xaml.cs:
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace UpdateAgent
{
public partial class App : Application
{
Interfaces.IStartup Startup;
public App()
{
InitializeComponent();
Xamarin.Forms.DependencyService.Get<Interfaces.IStartup>().Init();
MainPage = new WebUpdatePage();
}
}
}
Visual Studio 2019 for Mac 是最新版本。前几天刚更新,当我检查更新时没有任何更新。
我使用的是 iPhone XS Max 而不是模拟器。
看到评论后,我在模拟器中试用了 iPhone 12 Pro Max - 14.2,只是想看看它是否有任何不同。它做同样的事情。
更新 2:决定添加 WebUpdatePage xaml 并确定最终会要求它的类。他们来了:
WebUpdatePage.xaml:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:HybridWebViewMobile;assembly=HybridWebViewMobile"
x:Class="UpdateAgent.WebUpdatePage"
BackgroundColor="Black">
<ContentPage.Content>
<local:HybridWebView x:Name="hybridWebView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
</ContentPage.Content>
</ContentPage>
WebUpdatePage.xaml.cs:
using Xamarin.Forms;
using Devices.Communication.Mobile;
namespace UpdateAgent
{
public partial class WebUpdatePage : ContentPage
{
public WebUpdatePage()
{
InitializeComponent();
DependencyService.Get<IConnectDevice>().RegisterDetectors(hybridWebView).Wait();
DependencyService.Get<IConnectDevice>().Jsonfunctions(hybridWebView);
}
}
}
更新 3:
以下是有关 HybridWebView 的信息:
第一个 iOS 类是这样的:
[assembly: ExportRenderer(typeof(HybridWebView),typeof(HybridWebViewRenderer))]
namespace UpdateAgent.iOS
{
public class HybridWebViewRenderer : HybridWebViewRendererMobile
{
public HybridWebViewRenderer()
{
}
}
}
第二个 iOS 实现部分如下所示(仅显示相关部分):
public class HybridWebViewRendererMobile : WkWebViewRenderer, IWKScriptMessageHandler
{
const string JavaScriptFunction = "function invokeCSharpAction(data){window.webkit.messageHandlers.invokeAction.postMessage(data);}";
WKUserContentController userController;
public HybridWebViewRendererMobile() : this(new WKWebViewConfiguration())
{
}
public HybridWebViewRendererMobile(WKWebViewConfiguration config) : base(config)
{
userController = config.UserContentController;
var script = new WKUserScript(new NSString(JavaScriptFunction), WKUserScriptInjectionTime.AtDocumentEnd, false);
userController.AddUserScript(script);
userController.AddScriptMessageHandler(this, "invokeAction");
}
解决方案
推荐阅读
- android - Instant Apps:在特定设备 Xiaomi Redmi S2 (Android 8.1) 上的 Instant App 中使用 DialogFragments 或 AlertDialogs 时出现问题
- angular - ng-zorro cascader 延迟加载数据,nzLoadData 函数得到 this=undefined
- android - TextInputLayout 在包含文本时更改边框颜色
- typo3 - TypoScript 常量使用的语法和“扩展配置”的语法有什么区别吗?
- sql - 如何删除 SQL 表列中具有相同 Word 的其他行
- java - 如果达到某个值,如何将 for 循环内的布尔值设置为 true?
- javascript - 从对象中提取值
- servicestack - JSONB - 按索引更新数组值
- regex-group - 一种正则表达式,用于捕获由一个空格字符分隔的单词,并结合相反的捕获出现的多个空格字符
- html - 设置 CSS 悬停查询时,如何覆盖 CDN 派生的悬停规则?