這里我先簡單描述一下需求:服務器返回的是html頁面的一部分帶有標簽的內(nèi)容。
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名與空間、網(wǎng)站空間、營銷軟件、網(wǎng)站建設、天祝藏族自治網(wǎng)站維護、網(wǎng)站推廣。解決的思路是:將服務器返回的內(nèi)容片段拼湊成一個完整的頁面。
下面直接上核心代碼:
這里是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(); }