Android中使用WebView, WebChromeClient和WebViewClient加载网页
来源:互联网 发布:sql截取日期的年月日 编辑:程序博客网 时间:2024/05/21 11:06
在android应用中,有时要加载一个网页,如果能配上一个进度条就更好了,而android
等等,具体参考API
而进度条的使用是在new出一个setWebChromeClient后,可以在内部类中写
onProgressChanged事件
在WebView的设计中,不是什么事都要WebView类干的,有些杂事是分给其他人的,这样WebView专心干好自己的解析、渲染工作就行了。WebViewClient就是帮助WebView处理各种通知、请求事件的,具体来说包括:
中提供了其很好的支持
<?xml version="1.0" encoding="utf-8"?><WebView xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/webView" android:layout_width="fill_parent"android:layout_height="fill_parent" />主程序:
public class WebPageLoader extends Activity { final Activity activity = this; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.getWindow().requestFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.main); WebView webView = (WebView) findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSupportZoom(true); webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setTitle("Loading..."); activity.setProgress(progress * 100); if(progress == 100) activity.setTitle(R.string.app_name); } } ); webView.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // Handle the error } public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); webView.loadUrl("http://www.sohu.com"); } }
要注意的是,其中的webView的一系列用法,比如 webView.getSettings().setJavaScriptEnabled(true);设置可以使用javscript;
webView.getSettings().setJavaScriptEnabled(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setHorizontalScrollBarEnabled(false); webView.getSettings().setSupportZoom(true); webView.getSettings().setBuiltInZoomControls(true); webView.setInitialScale(70); webView.setHorizontalScrollbarOverlay(true);
等等,具体参考API
而进度条的使用是在new出一个setWebChromeClient后,可以在内部类中写
onProgressChanged事件
在WebView的设计中,不是什么事都要WebView类干的,有些杂事是分给其他人的,这样WebView专心干好自己的解析、渲染工作就行了。WebViewClient就是帮助WebView处理各种通知、请求事件的,具体来说包括:
onLoadResource onPageStart onPageFinish onReceiveError onReceivedHttpAuthRequest WebChromeClient是辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等 onCloseWindow(关闭WebView) onCreateWindow() onJsAlert (WebView上alert是弹不出来东西的,需要定制你的WebChromeClient处理弹出) onJsPrompt onJsConfirm onProgressChanged onReceivedIcon onReceivedTitle
0 0
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- 使用WebView, WebChromeClient和WebViewClient加载网页
- 使用WebView, WebChromeClient和WebViewClient加载网页
- Android使用WebView, WebChromeClient和WebViewClient加载网页
- android:使用WebView, WebChromeClient和WebViewClient加载网页
- android WebView, WebChromeClient和WebViewClient加载网页基本用法
- android WebView, WebChromeClient和WebViewClient加载网页基本用法
- android WebView, WebChromeClient跟WebViewClient加载网页基本用法
- ThinkPHP学习笔记(一)
- uva10474大理石在哪儿where is the marble?
- android 事件分发 结论
- Shiro异常1:java.lang.IllegalArgumentException: Line argument must contain a key and a value. Only one
- nosql
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- POJ 2533 Longest Ordered Subsequence
- 优化网站加载速度的14个技巧
- 用NAT实现外网对内网服务器的访问
- Shadow DOM 与 HTML Templates
- android assets/raw 大文件读取
- 环形缓冲区
- postgres插入默认值 如果select查询不到默认值
- 声道