我在一个布局中使用 8 - 10 个不同的 WebView,并在每个 WebView 中加载不同的内容。
加载 Webview 时会显示不同的消息,例如“正在加载..”“处理中..”等。
有什么办法可以隐藏这些通知吗?
我在一个布局中使用 8 - 10 个不同的 WebView,并在每个 WebView 中加载不同的内容。
加载 Webview 时会显示不同的消息,例如“正在加载..”“处理中..”等。
有什么办法可以隐藏这些通知吗?
尝试使用HttpClient
获取网页的html代码,然后使用WebView.loadData
将整个页面加载到WebView中。
private class exampleHttpTask extends AsyncTask<Integer, Integer, String> {
public String convertStreamToString(InputStream is, String charset) throws IOException {
if (is != null) {
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(new InputStreamReader(is, charset));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
is.close();
}
return writer.toString();
} else {
return "";
}
}
protected String doInBackground(Integer... params) {
String r = "";
try {
HttpClient hc = new DefaultHttpClient();
HttpGet get = new HttpGet("http://google.com"); // replace with the url
HttpResponse hr = hc.execute(get);
if(hr.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
InputStream is = hr.getEntity().getContent();
r = convertStreamToString(is, "UTF-8");
} else {
r = "Error";
}
} catch(Exception e){
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result) {
WebView wv = (WebView) findViewById(R.id.web_view); // replace web_view with the webView id
wv.loadData(result, "text/html", "utf-8");
}
protected void onPreExecute() {
}
}
然后调用new exampleHttpTask().exec()
加载网页。