亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請教,為什么Web View加載不出網頁

請教,為什么Web View加載不出網頁

波斯汪 2019-07-14 08:08:48
請教,為什么Web View加載不出網頁
查看完整描述

3 回答

?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

檢查一下webview的方法調用對沒有!
網頁腳本js運行出錯,webView.setWebViewClient用WebViewClient的onPageFinished(WebView view, String url)方法會監聽到網頁加載完成,如果顯示不完整,就應該去找網頁怎么寫的。

WebViewClient的方法說明
1、public
boolean shouldOverrideUrlLoading(WebView view, String url) {

view.loadUrl(url);

return true;

}

在點擊請求的是鏈接是才會調用,重寫此方法返回true表明點擊網頁里面的鏈接還是在當前的webview里跳轉,不跳到瀏覽器那邊。
2、public
void onReceivedSslError(WebView view, SslErrorHandler handler,
android.net.http.SslError error) {
handler.proceed();
}
重寫此方法可以讓webview處理https請求。
3、public
boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {

return super.shouldOverrideKeyEvent(view, event);

}

}
重寫此方法才能夠處理在瀏覽器中的按鍵事件。
4、
public void onLoadResource(WebView view, String url) {

// TODO Auto-generated method stub

if (DEBUG) {

Log.d(TAG, " onLoadResource ");

}

super.onLoadResource(view, url);

}
在加載頁面資源時會調用,每一個資源(比如圖片)的加載都會調用一次。
5、
public void onPageStarted(WebView view, String url, Bitmap favicon) {

// TODO Auto-generated method stub

if (DEBUG) {

Log.d(TAG, " onPageStarted ");

}

if (url.endsWith(".apk")) {

download(url);//下載處理

}

super.onPageStarted(view, url, favicon);

}
在頁面加載開始時調用。
6、public
void onPageFinished(WebView view, String url) {

// TODO Auto-generated method stub

if (DEBUG) {

Log.d(TAG, " onPageFinished ");

}

super.onPageFinished(view, url);

}
在頁面加載結束時調用。
webview介紹的原文如下:A View that displays web pages. This class is the basis upon which you can roll your own web browser or simply display some online content within your Activity. It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more.
從上面你應該了解到了基本功能,也就是顯示網頁。之所以我說webview功能強大是因為它和js的交互非常方便,很簡單就可以實現。


查看完整回答
反對 回復 2019-07-15
?
偶然的你

TA貢獻1841條經驗 獲得超3個贊

UIWebView加載工程本地網頁與本地圖片

- (void)viewDidLoad
{
[super viewDidLoad];

NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

myWebView = [[UIWebView alloc] initWithFrame:self.view.bounds];
myWebView.delegate = self;
[self.view addSubview:myWebView];

[myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];

}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString * js = [NSString stringWithFormat:@"document.images[0].src='file:/%@//%@'",imagePath,@"icon-04.png"];

[myWebView stringByEvaluatingJavaScriptFromString:js];
NSString *path = [myWebView stringByEvaluatingJavaScriptFromString:@"document.images[0].src"];
NSLog(@"path:%@", path);
}

 

查看完整回答
反對 回復 2019-07-15
?
茅侃侃

TA貢獻1842條經驗 獲得超21個贊

android中只需要給webView注冊一個事件即可實現加載進度。
以下是具體實現代碼:
1.從webView中獲取設置
WebSettings sws = webView.getSettings();
sws.setSupportZoom(true);
sws.setBuiltInZoomControls(true);
webView.setInitialScale(25);
webView.getSettings().setUseWideViewPort(true);

2.注冊setWebChromeClient事件
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activity和Webview根據加載程度決定進度條的進度大小
// 當加載到100%的時候 進度條自動消失
//WebViewProgressActivity.this.setTitle("Loading...");
//WebViewProgressActivity.this.setProgress(progress * 100);
if (progress == 100) {
progressBar.setVisibility(View.GONE);
//WebViewProgressActivity.this.setTitle("完成");
}
}
});

3.注意在onProgressChanged中處理進度,progress就是進度值。


查看完整回答
反對 回復 2019-07-15
  • 3 回答
  • 0 關注
  • 1872 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號