标签:des android style blog http io ar color os
主程序:
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); //点击链接在当前browser中响应,而不是新开Android系统browser中响应该链接 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类干的,有些杂事是分给其他人的,这样WebView专心干好自己的解析、渲染工作就行了。WebViewClient 就是帮助WebView处理各种通知、请求事件的,具体来说包括:
WebChromeClient是辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等
效果图如下:
代码如下:
标签:des android style blog http io ar color os
原文地址:http://blog.csdn.net/u011742151/article/details/41721573