使用 Xamarin Forms 更新到 AppCompat 后 WebView 中的白色覆盖

White overlay in WebView after update to AppCompat with Xamarin Forms

在我的 Xamarin Forms 应用程序中,我通过插入 contentEditable 设置为 true 的 div 将 WebView 用作表单。在更新 AppCompat 样式之前一切正常。

现在,当用户尝试在 WebView 内书写时,会出现一个奇怪的白色覆盖层(白色方块),当关闭键盘时该覆盖层会消失。为了找到问题的根本原因,我创建了一个示例项目,其中只有一个页面仅包含一个垂直堆栈布局,其中包含另一个堆栈布局和 web 视图。我注意到的是,如果内部堆栈布局的高度足以让 webview 在出现时被键盘覆盖,则会发生此问题。在这种情况下,webview 被向上推,并且出现了这个奇怪的叠加层。 Web 视图功能齐全,可以编写文本,即使它被这个白色方块隐藏了,当键盘关闭时它会消失。

这是可用于测试问题的简单页面示例。添加按钮只是为了增加和减少布局的大小,以更容易地显示问题

public class MainPage : ContentPage
{
    const string ContentEdit = @"<div contentEditable=""true"" style =""min-height: 200px"">";
    const string ContentEditEnd = "</div>";
    const string EmptyDocument = @"<body>" + ContentEdit + ContentEditEnd + @"</body>";

    WebView webView;

    public MainPage()
    {
        InitializePage();
    }

    void InitializePage()
    {
        webView = new WebView()
        {
            VerticalOptions = LayoutOptions.FillAndExpand,
            HorizontalOptions = LayoutOptions.FillAndExpand,
        };

        var button1 = new Button
        {
            HorizontalOptions = LayoutOptions.CenterAndExpand,
            VerticalOptions = LayoutOptions.CenterAndExpand,
            Text = "-",
        };

        var button2 = new Button
        {
            HorizontalOptions = LayoutOptions.CenterAndExpand,
            VerticalOptions = LayoutOptions.CenterAndExpand,
            Text = "+",
        };

        var tallLayout = new StackLayout()
        {
            Orientation = StackOrientation.Horizontal,
            HeightRequest = 200, 
            BackgroundColor = Color.Lime,
            Children = { button1, button2, },
        };

        button1.Clicked += (sender, e) => tallLayout.HeightRequest = tallLayout.Height - 20;
        button2.Clicked += (sender, e) => tallLayout.HeightRequest = tallLayout.Height + 20;

        var layout = new StackLayout
        {
            Orientation = StackOrientation.Vertical,
            VerticalOptions = LayoutOptions.FillAndExpand,
            HorizontalOptions = LayoutOptions.FillAndExpand,
            Children = { tallLayout, webView },
        };

        Content = layout;
    }

    protected override void OnAppearing()
    {
        InitializeEmptyContent();
    }

    public void InitializeEmptyContent()
    {
        var htmlSource = new HtmlWebViewSource();
        htmlSource.Html = EmptyDocument;

        webView.Source = htmlSource;
    }
}

我也尝试过使用原生 Android 重现这个简单的布局,但似乎我没有任何类似的错误。这是 Xamarin Forms 错误还是我做错了什么?

最终问题被识别为 Xamarin bug