创建两个类文件,如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
Home.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;
}
}
Android清单
只需添加活动类,并设置Internet权限加载网页视图
可能有机会,你在代码中犯的错误。 –
也许你有分开,检查显示文件, –
@TomerMor你可以详细说明评论吗? –