English 中文(简体)
MauiWebChrome 客户不启动方案 改变
原标题:MauiWebChromeClient not triggering OnProgressChanged

试图在网上浏览中发现页装上的进展情况。

这是我的主食法典。

namespace MauiApp2 {
    public partial class MainPage : ContentPage
    {
        int count = 0;

        public MainPage()
        {
            InitializeComponent();
        }
        void mywebview_Navigating(System.Object sender, Microsoft.Maui.Controls.WebNavigatingEventArgs e)
        {
#if ANDROID

            Microsoft.Maui.Handlers.WebViewHandler.Mapper.AppendToMapping("Custom", (handler, view) =>
            {
                handler.PlatformView.Settings.CacheMode = Android.Webkit.CacheModes.Default;
                handler.PlatformView.Settings.SetAppCacheEnabled(true);
                handler.PlatformView.Settings.JavaScriptEnabled = true;
                handler.PlatformView.SetWebChromeClient(new CustomWebViewClient(handler));
            });  
#endif
        }
    } }

and my CustomWebViewCLient.cs :

using Android.App;
using Android.Graphics;
using Android.Views;
using Android.Webkit;
using MauiApp2.Services;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebView = Android.Webkit.WebView;


    namespace MauiApp2.Platforms.Android
    {
        public class CustomWebViewClient : MauiWebChromeClient
        {
            private readonly Activity context;
            SpinnerPopup popup = new SpinnerPopup();
    
            public CustomWebViewClient(IWebViewHandler handler) : base(handler)
            {
                this.context = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
            }
            public override void OnProgressChanged(WebView view, int newProgress)
            {
                Console.WriteLine(newProgress);
            }
    
        }
    }

产出窗口没有显示什么,而网页却装满。

问题回答

您可尝试将守则列入。 方法,如:

In the xaml:

<WebView x:Name="web" Source="" HeightRequest="800"/>

以及以下法典:

protected override void OnHandlerChanged()
{
    base.OnHandlerChanged();

#if ANDROID
   var webview = web.Handler.PlatformView as Android.Webkit.WebView;
   webview.Settings.CacheMode = Android.Webkit.CacheModes.Default;
   webview.Settings.SetAppCacheEnabled(true);
   webview.Settings.JavaScriptEnabled = true;
   webview.SetWebChromeClient(new CustomWebViewClient(web.Handler as WebViewHandler));
#endif
}

可在<代码>上添加一个空白点。 关于ProgressChanged 方法,如果被点到或没有。





相关问题
Unable to access file in ResourcesSounds folder

I m using .net Maui and attempting to create audioManager players for a couple of sound files located in the ResourcesSounds folder in the project. The code is this: var playerStartSound = ...

.NET MAUI native audio player

I am interested is there a way to play mp3 files from the phone internal memory using the built in native audio player. I am asking this, because I want to implement an equalizer too, so I am guessing ...

Integrating Push Notifications in MAUI .NET 7 Applications

I m developing a cross-platform application using MAUI .NET 7 and I would like to add push notification functionality to my application. I m considering using Firebase Cloud Messaging or Azure ...

Databinding doesnt work in my xaml.cs file

I am trying to load some data from my Model to the xaml.cs file. But it doesn t work. In my Mainpage.xaml i have a binding property inside a label. In the code behind file a BindingContext to my ...

Do some tasks after OnAppearing() in MAUI

I have a maui community toolkit expander control in my page. On Tapping the header the content is shown/hidden .I got a Maui map in the expander s content. It display properly if the expander is in ...

NET MAUI是否有可调整的分辨率特征?

页: 1 NET MAUI用于一个即将到来的项目,但我发现一件失踪的事情是,我需要的是分裂的特征。 我发现,散射器在移动上可能不会产生作用,但Im主要针对Windows......。

How to optimize detail page reset button in C# MAUI?

I ve implemented a Reset button on a Detail page in C# MAUI and it works, but I can t figure out why I need to be so explicit in the way I capture the initial data to perform the reset, when requested....

热门标签