1
如何使用Mono for Android打开网站?我假设我需要使用一个意图,但我不知道哪一个。如何使用MonoDroid打开网站?
如何使用Mono for Android打开网站?我假设我需要使用一个意图,但我不知道哪一个。如何使用MonoDroid打开网站?
var intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://www.stackoverflow.com"));
StartActivity(intent);
另一种可能性是创建一个web视图并加载一个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;
}
}
}
}
您在这里有一吨的可能性。
只是展示了WebView为您提供的一些可能性。你可以简单地省去你不需要的代码。 – Cheesebaron 2012-01-10 15:06:06