3 回答
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的交互非常方便,很简单就可以实现。
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);
}
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就是进度值。
- 3 回答
- 0 关注
- 1822 浏览
添加回答
举报