并且比较强大的是,还可以直接跟js相互调用。 webview有两个方法:setWebChromeClient和setWebClient setWebChromeClient主要处理解析,渲染网页等浏览器做的事情 WebChromeClient是辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等 比如可以添加进度条,使得界面更友好 webview1.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { setProgress(progress * 100); if(progress == 100){ imageView1.setVisibility(View.GONE); tv1.setVisibility(View.GONE); pb1.setVisibility(View.GONE); fy1.setVisibility(View.GONE); } } } );
onLoadResource 例如: webview1.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // Handle the error Toast.makeText(getApplicationContext(), "网络连接失败 ,请连接网络。", Toast.LENGTH_SHORT).show(); } public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); //设置字符集编码webview1.getSettings().setDefaultTextEncodingName("UTF-8"); webview1.loadUrl("http://www./"); |
|