这里我先简单描述一下需求:服务器返回的是html页面的一部分带有标签的内容。
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、网站空间、营销软件、网站建设、天祝藏族自治网站维护、网站推广。解决的思路是:将服务器返回的内容片段拼凑成一个完整的页面。
下面直接上核心代码:
这里是WebView一些配置
WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); webView.setWebViewClient(new MyWebViewClient(activity)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); } else { settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); } webView.loadData(getHtmlData(item.content), "text/html;charset=utf-8","utf-8"); private String getHtmlData(String bodyHTML) { String head = "" + " " + "" + ""; return "" + head + "" + bodyHTML + ""; } static class MyWebViewClient extends WebViewClient{ private WaitingDialog dialog; private Activity activity; public MyWebViewClient(Activity activity){ dialog = new WaitingDialog(activity); this.activity = activity; } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { LogUtil.e(url); view.loadUrl(url); return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if(!activity.isFinishing()) dialog.show(); } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); super.onReceivedSslError(view, handler, error); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if(!activity.isFinishing()) dialog.dismiss(); }