【发布时间】:2021-08-01 14:57:55
【问题描述】:
我需要帮助。导航和导航代码在我的项目中不起作用。页面已满时动画不会被删除。外部链接在设备浏览器中不起作用。我的代码:
public MainPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
webViewElement.Source = "https://mywebsite.com/";
webViewElement.RegisterAction(ExecuteActionFromJavascript);
_deviceFeaturesHelper = new DeviceFeaturesHelper();
}
void WebOnNavigating(object sender, WebNavigatingEventArgs args)
{
loading.IsVisible = true;
if (args.Url.StartsWith("https://mywebsite.com/"))
{
return;
}
else
{
Device.OpenUri(new Uri(args.Url));
args.Cancel = true;
}
}
void WebOnNavigated(object sender, WebNavigatingEventArgs s)
{
loading.IsVisible = false;
}
protected override bool OnBackButtonPressed()
{
webViewElement.GoBack();
return true;
}
是的,导航事件不会触发。是的,我在我的安卓设备上测试了这个应用程序。对不起我的英语.. 我的 xaml:
<ContentPage.Content>
<AbsoluteLayout>
<StackLayout AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1">
<controls:HybridWebView
x:Name="webViewElement"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Navigating="WebOnNavigating"
Navigated="WebOnNavigated"/>
</StackLayout>
<Frame AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds="0.5,0.5,AutoSize,AutoSize"
x:Name="loading"
BackgroundColor="Gray"
Opacity="0.9"
IsVisible="True">
<StackLayout>
<ActivityIndicator IsRunning="True"/>
<Label Text="Loading..." TextColor="White"/>
</StackLayout>
</Frame>
</AbsoluteLayout>
</ContentPage.Content>
【问题讨论】:
-
“不工作”不是对问题的有用描述。这具体是什么意思?您采取了哪些调试步骤来诊断问题?
-
do not work是否意味着导航事件不触发?您是否在 xaml 中分配事件?你是在安卓模拟器还是真机上测试过?你那边xamarin.forms是什么版本的? -
是的,导航事件不会触发。是的,我在我的安卓设备上测试了这个应用程序。对不起我的英语..
-
我的 xaml:
-
请提供
HybridWebView类的代码和相关的自定义渲染器代码,以便我们测试。
标签: c# android xamarin xamarin.forms