问题
I am using 8 - 10 different WebViews in one layout and loading different content in each WebView.
While loading Webview shows different messages like "Loading.." "Processing.." etc.
Is there any way to hide these notifications?
回答1:
Try to use HttpClient to get the webpage's html code and then use WebView.loadData to load the entire page into 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() {
}
}
Then call new exampleHttpTask().exec() to load the webpage.
来源:https://stackoverflow.com/questions/13915354/how-to-hide-android-webview-notifications