webview可以获取网页源码,进行重新排版吗

来源:互联网 发布:php 序列化 编辑:程序博客网 时间:2024/06/05 19:41
 private void getHtml_data(String Url, int FontSize) {

                String text = "";
                try {
                        URL url = new URL(Url);
                        URLConnection conn;

                        conn = url.openConnection();
                        // Get the response
                        BufferedReader rd = new BufferedReader(new InputStreamReader(conn
                                        .getInputStream()));
                        String line = "";
                        String data = "";
                        while ((line = rd.readLine()) != null) {
                                Message lmsg;
                                lmsg = new Message();
                                lmsg.obj = line;
                                lmsg.what = 0;

                                data = data + (String) lmsg.obj;
                        }
                        text = data.replace("<body>", "<body style=\"font-size:" + FontSize
                                        + "px;\">");
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                myWebView.loadDataWithBaseURL("", text, "text/html", "UTF-8", null);

        }

data就是你要的网页源码,text修改(就像我在body 加上size)
最后用myWebView.loadDataWithBaseURL("", text, "text/html", "UTF-8", null);