Xamarin webview 不填满屏幕
Xamarin webview does not fill screen
我目前正在创建一个 Xamarin Forms 应用程序,它具有一个必须覆盖我的整个设备屏幕的 webview。
不幸的是我不知道该怎么做,我的下面总是有一个白色的条,这是一个错误吗?我关闭了导航栏,因为我不想显示它。
我按照解释 here
使用了混合 webview
我已经尝试过使用网格、堆栈布局和绝对布局,
更新
已经尝试在布局和 webview 中将 padding 和 margin 设置为 0,也不起作用..
我当前的布局如下所示:
<?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:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:EatyAndroidApp.Controls"
mc:Ignorable="d"
x:Class="EatyAndroidApp.CustomWebViewPage"
NavigationPage.HasNavigationBar="False"
NavigationPage.HasBackButton="False"
BackgroundColor="#313131">
<ContentPage.Content>
<StackLayout HorizontalOptions="Fill" VerticalOptions="Center">
<controls:HybridWebView
x:Name="hybridWebView"
BackgroundColor="#313131"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
这让我产生了这个:(我模糊了内容)
Image
提前致谢
好的,我想通了,不知何故,webview 不知道它的高度和宽度,我不得不通过 Javascript 手动访问它并设置新的布局:
里面
public override async void OnPageFinished(Android.Webkit.WebView view, string url)
只需执行
view.EvaluateJavascript("document.documentElement.style.height = screen.height + 'px';", null);
我目前正在创建一个 Xamarin Forms 应用程序,它具有一个必须覆盖我的整个设备屏幕的 webview。
不幸的是我不知道该怎么做,我的下面总是有一个白色的条,这是一个错误吗?我关闭了导航栏,因为我不想显示它。 我按照解释 here
使用了混合 webview我已经尝试过使用网格、堆栈布局和绝对布局,
更新 已经尝试在布局和 webview 中将 padding 和 margin 设置为 0,也不起作用..
我当前的布局如下所示:
<?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:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:EatyAndroidApp.Controls"
mc:Ignorable="d"
x:Class="EatyAndroidApp.CustomWebViewPage"
NavigationPage.HasNavigationBar="False"
NavigationPage.HasBackButton="False"
BackgroundColor="#313131">
<ContentPage.Content>
<StackLayout HorizontalOptions="Fill" VerticalOptions="Center">
<controls:HybridWebView
x:Name="hybridWebView"
BackgroundColor="#313131"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
这让我产生了这个:(我模糊了内容) Image
提前致谢
好的,我想通了,不知何故,webview 不知道它的高度和宽度,我不得不通过 Javascript 手动访问它并设置新的布局:
里面
public override async void OnPageFinished(Android.Webkit.WebView view, string url)
只需执行
view.EvaluateJavascript("document.documentElement.style.height = screen.height + 'px';", null);