向 Xamarin Forms WebView 添加背景颜色没有影响 [英] Adding background color to Xamarin Forms WebView has no impact

查看:34
本文介绍了向 Xamarin Forms WebView 添加背景颜色没有影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面标记

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage NavigationPage.HasNavigationBar="false" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="ConnectedLifeView.NativeApp.Pages.LoginSuccessPage">
    <ContentPage.Content>
        <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Margin="0" Padding="0">
            <WebView x:Name="webView" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#02114D"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

输出

我尝试向内容页面添加背景颜色并将 WebView 背景颜色设置为透明,但也没有效果.

I tried adding background color to content page and setting WebView background color to Transparent but it has no effect either.

我的所有其他页面都有适当的背景,但该页面看起来有点奇怪,因为它在 WebView 中加载 URL 时显示白色背景.

My all other pages have proper background but this page looks a bit weird as it shows white background while the URL loads in WebView.

Xamarin.Forms 版本:4.2.0.815419

Xamarin.Forms version: 4.2.0.815419

平台:安卓

推荐答案

如果你想改变 webview 的背景颜色,另一种方法是使用自定义渲染.

If you want to change webview background color, another way is to use custom render.

public class TransparentWebViewRenderer:WebViewRenderer

{
    protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
    {
        base.OnElementChanged(e);

        // Setting the background as transparent
        this.Control.SetBackgroundColor(Android.Graphics.Color.AliceBlue);
    }

}

这篇关于向 Xamarin Forms WebView 添加背景颜色没有影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆