使用WebViewClient和WebChromeClient的Android

使用WebViewClient和WebChromeClient的Android,android,xamarin,webviewclient,webchromeclient,Android,Xamarin,Webviewclient,Webchromeclient,我需要操纵html中的链接,所以我使用WebViewClient来完成。问题是我有一些iFrame加载本地html页面,但它们不会显示。 但是,如果我使用WebChromeClient,它们可以工作 所以,我想同时使用这两种方法,但都不起作用。似乎只有webViewClient可以工作,我不知道为什么 我在清单中设置了Internet权限并写入外部存储器(因为我的html位于存储器中),还启用了硬件加速 这是我的代码: public class BChromeClient : WebChrome

我需要操纵html中的链接,所以我使用WebViewClient来完成。问题是我有一些iFrame加载本地html页面,但它们不会显示。 但是,如果我使用WebChromeClient,它们可以工作

所以,我想同时使用这两种方法,但都不起作用。似乎只有webViewClient可以工作,我不知道为什么

我在清单中设置了Internet权限并写入外部存储器(因为我的html位于存储器中),还启用了硬件加速

这是我的代码:

public class BChromeClient : WebChromeClient
    {
        public BChromeClient ()
        {}

        public bool OnShowCustomView(WebView view, string url)
        {
            return true;
        }

        public void OnHideCustomView()
        {
        }


    }

    public class BWebClient : WebViewClient
    {
        int _position;
        string _path;
        Activity _parent;
        ViewPager _pager;
        string _chapName;
        public BWebClient (int position, string Path, Activity Parent, ViewPager Pager, string ChapName){
            _position = position;
            _parent = Parent;
            _path = Path;
            _pager = Pager;
            _chapName = ChapName;
        }

        public override void OnPageFinished (WebView view, string url)
        {
            base.OnPageFinished (view, url);
            view.ScrollTo (0, _position);
        }

        public override bool ShouldOverrideUrlLoading (WebView view, string url)
        {

            if (url.StartsWith ("navigate")) {
                string destination = url.Substring (url.IndexOf ("navigate://") + "navigate://".Length);
                int DestinationChapter = Int32.Parse (destination.Substring (0, destination.IndexOf("_")));
                int l = destination.IndexOf("_") + 1;
                int b = destination.Length - l;
                int DestinationPage = Int32.Parse (destination.Substring (l,b));



                if (DestinationPage == 0) {
                    _pager.SetCurrentItem(DestinationChapter ,true);
                    WebView _web = (WebView)_pager.FindViewWithTag(300 + DestinationChapter);
                    _web.LoadUrl ("file://" + _path + "/" + _chapName);
                }



            } else if (url.StartsWith ("pdf")) {
                string file_path = _path + url.Substring (5);
                if (System.IO.File.Exists(file_path)) {
                    Android.Net.Uri pdfFile = Android.Net.Uri.FromFile (new Java.IO.File (file_path));
                    Intent pdfIntent = new Intent (Intent.ActionView);
                    pdfIntent.SetDataAndType (pdfFile, "application/pdf");
                    pdfIntent.SetFlags (ActivityFlags.NoHistory);
                    _parent.StartActivity (pdfIntent);
                }
            }

            return true;
        }
    }
而在fragment OnCreateView方法中(是的,我在PageViewer中使用webview,但我认为知道这一点并不重要)

web\u view=view.findviewbyd(Resource.Id.webview);
web_view.SetWebChromeClient(新的BCChromeClient());
SetWebViewClient(新的BWebClient(_位置,_路径,_父项,_寻呼机,_chap.Name));
web_view.SetBackgroundColor(Color.Transparent);
web_view.Settings.JavaScriptEnabled=true;
web_view.Settings.AllowFileAccess=true;
//web_view.Settings.SetPluginState(WebSettings.PluginState.On);
在MainActivity.cs中

web_view..webviewClient = new ExtendedWebViewClient();
 web_view.SetWebChromeClient(new ExtendedChromeClient(MainActivity));
            web_view.SetWebViewClient(this.webviewClient);
web_view..webviewClient = new ExtendedWebViewClient();
 web_view.SetWebChromeClient(new ExtendedChromeClient(MainActivity));
            web_view.SetWebViewClient(this.webviewClient);