您的位置:首页 > 移动开发

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

2012-07-18 18:39 330 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: