如何使用Mono for Android打开网站?我假设我需要使用Intent,但我不知道哪一个。
答案 0 :(得分:4)
var intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://www.stackoverflow.com"));
StartActivity(intent);
答案 1 :(得分:2)
另一种可能性是创建WebView并在其中加载URL,这样您就可以更好地控制它的外观以及它对Javascript等内容的反应。
您可以像这样创建自己的活动:
using System;
using Android.App;
using Android.OS;
using Android.Webkit;
using Android.Views;
namespace WebViewSample
{
[Activity(Label = "MyAwesomeWebActivity", MainLauncher = true, Icon = "@drawable/icon")]
public class MyAwesomeWebActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
WebView webView = new WebView(this);
webView.Settings.JavaScriptEnabled = true;
webView.Settings.SetSupportZoom(true);
webView.Settings.BuiltInZoomControls = true;
webView.Settings.LoadWithOverviewMode = true; //Load 100% zoomed out
webView.ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
webView.ScrollbarFadingEnabled = true;
webView.VerticalScrollBarEnabled = true;
webView.HorizontalScrollBarEnabled = true;
webView.SetWebViewClient(new AwesomeWebClient());
webView.SetWebChromeClient(new AwesomeWebChromeClient(this));
AddContentView(webView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));
webView.LoadUrl("http://stackoverflow.com");
}
private class AwesomeWebClient : WebViewClient { }
private class AwesomeWebChromeClient : WebChromeClient
{
private Activity mParentActivity;
private string mTitle;
public AwesomeWebChromeClient(Activity parentActivity)
{
mParentActivity = parentActivity;
mTitle = parentActivity.Title;
}
public override void OnProgressChanged(WebView view, int newProgress)
{
mParentActivity.Title = string.Format("Loading {0}%", newProgress);
mParentActivity.SetProgress(newProgress * 100);
if (newProgress == 100) mParentActivity.Title = mTitle;
}
}
}
}
你在这里有很多可能性。