简体   繁体   English

如何隐藏Android WebView通知?

[英]How to Hide Android WebView Notifications?

I am using 8 - 10 different WebViews in one layout and loading different content in each WebView. 我在一种布局中使用8-10个不同的WebView,并在每个WebView中加载不同的内容。

While loading Webview shows different messages like "Loading.." "Processing.." etc. 加载Webview时会显示不同的消息,例如“正在加载..”,“正在处理...”等。

在此处输入图片说明

Is there any way to hide these notifications? 有什么办法可以隐藏这些通知吗?

Try to use HttpClient to get the webpage's html code and then use WebView.loadData to load the entire page into 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() {
    }

}

Then call new exampleHttpTask().exec() to load the webpage. 然后调用new exampleHttpTask().exec()来加载网页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM