XAML 向Xamarin Forms WebView添加背景颜色没有影响

ds97pgxw  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(132)

页面标记

<?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背景颜色设置为透明,但也没有效果。
我的所有其他页面都有适当的背景,但这个页面看起来有点奇怪,因为它显示白色背景,而在WebView中加载的URL。
Xamarin.表格版本:4.2.0.815419
平台:安卓

lyr7nygr

lyr7nygr1#

如果你想改变网页视图的背景颜色,另一种方法是使用自定义渲染。

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);
    }

}

相关问题