创建两个类文件,如 WebActivity.java、home.java。
WebActivity.java
Handler handler = new Handler();
// run a thread after 2 seconds to start the home screen
handler.postDelayed(new Runnable() {
@Override
public void run() {
// make sure we close the splash screen so the user won't come
// back when it presses back key
finish();
// start the home screen
ProgressDialog pd = new ProgressDialog(WebActivity.this);
//use this before calling intent
pd.setMessage("Processing...");
pd.show();
Intent intent = new Intent(WebActivity.this, Home.class);
WebActivity.this.startActivity(intent);
}
}, 2000); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called
主页.java
webview=(WebView)findViewById(R.id.webView1);
webview.setWebViewClient(new myWebClient());
webview.loadUrl("http://www.google.com");}
public class myWebClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}
安卓清单
只需添加活动类并设置互联网权限即可加载 webview