不使用webview打开网页

时间:2014-12-22 15:50:14

标签: xamarin xamarin.forms

我想在设备上使用webbrowser打开一个网页。现在我使用WebView,但我想让用户在Chrome,Safari或设备上当前的任何其他web浏览器之间进行选择。 有没有办法做到这一点?

4 个答案:

答案 0 :(得分:15)

var url = "http://www.google.com";
Device.OpenUri(new Uri(url));

这使用默认浏览器打开网址。

来源:https://forums.xamarin.com/discussion/comment/94202#Comment_94202

API文档:Xamarin.Forms.Device.OpenUri

答案 1 :(得分:2)

我正在使用此代码:

var uri = Android.Net.Uri.Parse ("http://www.google.com");
var intent = new Intent (Intent.ActionView, uri); 
StartActivity (intent);

紧凑版:

StartActivity (new Intent (Intent.ActionView, Android.Net.Uri.Parse ("http://www.google.com"))); 

答案 2 :(得分:0)

简单的解决方案,

WebView web_view;

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        SetContentView (Resource.Layout.Social);


        web_view = FindViewById<WebView> (Resource.Id.webView);
        web_view.Settings.JavaScriptEnabled = true;
        web_view.SetWebViewClient (new HelloWebViewClient ());
        web_view.Settings.LoadWithOverviewMode = true;
        web_view.Settings.UseWideViewPort = true;
        web_view.LoadUrl ("http://www.facebook.com");


    }

    public class HelloWebViewClient : WebViewClient
    {
        public override bool ShouldOverrideUrlLoading (WebView view, string url)
        {
            view.LoadUrl (url);
            return true;
        }
    }

答案 3 :(得分:-2)

我认为它是打开您想要的网页的默认网络浏览器。

试着这样看。