2012-12-17 75 views
1

我在一個佈局中使用8-10個不同的WebView,並在每個WebView中加載不同的內容。如何隱藏Android WebView通知?

雖然加載網頁視圖顯示不同的類似的消息「中..」「處理......」等

enter image description here

有什麼辦法來隱藏這些通知?

回答

1

嘗試使用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()加載網頁。

+0

這將與網頁(連接到互聯網)一起使用,但在您想從資產中加載頁面時不起作用。看到我的問題在這裏:http://stackoverflow.com/q/17145969/1031312 – Ozzy

+0

@Ozzy我有類似的問題,從資產加載和避免閃爍多個webviews。您是否找到任何解決方案? – Gaurav