![](/img/trans.png)
[英]Can you measure the time it takes to load a web page in a webView in Android?
[英]load web page in webview (android)
我試圖加載網頁webview
,但它不是在加載網頁webview
相反,它是要求其他瀏覽器的應用程序加載網頁
我想在我的應用程序webview
加載網頁
這是我的代碼:它要求另一個應用程序加載頁面
package com.example.webview;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.webkit.WebView;
public class MainActivity extends ActionBarActivity {
private WebView browser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
browser = (WebView) findViewById(R.id.webView1);
browser.loadUrl("http://www.google.com");
}
}
您尚未設置webviewclient,因此請使用以下代碼進行設置。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
browser = (WebView) findViewById(R.id.webView1);
browser .setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
});
browser.loadUrl("http://www.google.com");
}
您缺少以下行。 在調用webview的ID后添加它,然后它將起作用:
browser.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
.....
}
您可以嘗試此方法,希望它會對您有所幫助。
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class Main extends Activity {
private WebView mWebview ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
final Activity activity = this;
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
mWebview .loadUrl("http://www.google.com");
setContentView(mWebview );
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.