Xamarin Webview不会启动新标签

时间:2017-01-21 11:49:37

标签: android xamarin webview

我正在玩xamarin android webview,我遇到了这个问题.webview没有打开设置为在新标签页中打开的页面。例如,stackoverflow上的作业广告设置为在新选项卡中打开,当您触摸它们时没有任何反应!谢谢你的进步,这是我的代码。

 [Activity(MainLauncher = false, Theme = "@android:style/Theme.NoTitleBar")]
public class Obs_Activity : Activity
{
    WebView web_view;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.sist);
        web_view = FindViewById<WebView>(Resource.Id.webview);
        web_view.Settings.SetSupportMultipleWindows(false);
        web_view.Settings.UseWebViewBackgroundForOverscrollBackground = true;
        web_view.Settings.PluginsEnabled = true;
        web_view.Settings.AllowFileAccess = true;
        web_view.Settings.DisplayZoomControls = true;
        web_view.SetWebViewClient(new HelloWebViewClient(this));


        web_view.Settings.JavaScriptEnabled = true;
        web_view.Settings.JavaScriptCanOpenWindowsAutomatically = true;
        web_view.Settings.SetSupportZoom(true);
        web_view.LoadUrl("http://obs.kku.edu.tr/");
    }




}
public class HelloWebViewClient : WebViewClient
{
    public Activity mActivity;
    public HelloWebViewClient(Activity mActivity)
    {
        this.mActivity = mActivity;
    }
    public override bool ShouldOverrideUrlLoading(WebView view, string url)
    {
        view.LoadUrl(url);
        Toast.MakeText(mActivity, "Yukleniyor...",
                             ToastLength.Long).Show();
        return true;
    }

    public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm)
    {
        base.OnReceivedHttpAuthRequest(view, handler, host, realm);
        Toast.MakeText(mActivity, "Hata", ToastLength.Long).Show();
    }
}
  

01-23 13:02:36.695 D / WebViewCallback(16789):shouldInterceptRequest = http://ogrenciportal.kku.edu.tr/getinfo.ashx?id=3&tt=690   01-23 13:02:36.711 D / WebViewCallback(16789):onLoadResource = http://ogrenciportal.kku.edu.tr/getinfo.ashx?id=3&tt=690   01-23 13:02:36.712 D / WebViewCallback(16789):doUpdateVisitedHistory = http://ogrenciportal.kku.edu.tr/Default.aspx# reload = false   01-23 13:02:36.740 D / WebViewCallback(16789):onPageFinished,url = http://ogrenciportal.kku.edu.tr/Default.aspx#

当我按下该链接并且没有任何反应时,这是日志。

1 个答案:

答案 0 :(得分:0)

如果您需要自己实现标签式浏览器UI,WebView不支持标签

您将SetSupportMultipleWindows设置为true,但未实施WebChromeClient及其OnCreateWindow方法。

  

设置WebView是否支持多个窗口。如果设置为true,则必须由宿主应用程序实现onCreateWindow(WebView,boolean,boolean,Message)。

  • 如果您希望Apply Now / JavaScript弹出窗口显示在新页面中,请继续使用WebViewClient,但将SetSupportMultipleWindows设置为 false

  • 如果您想在标签中打开新的WebView,则需要实施WebChromeClient子类并覆盖OnWindowCreate并通过WebView.SetWebChromeClient进行设置否则链接将在默认的系统Web浏览器中打开。