Webview inside RecyclerView is showing blank screen sometimes on Nougat devices only

Viewed 4666

In my Nougat device, webview inside RecyclerView is blank sometimes. When I scroll slowly and then go back to webview item content disappear. There is no issue on devices below Android N. Android N uses Chrome as the default browser for apps. So I thought there might be a bug in Chrome so I raise a bug in chrome portal as well. There are a couple of related question in SO but that didn't solve my problem. So is there a way in Android webview setting which can solve this problem? I have written detail description in the bug link.

Bug link: click here

My onBindViewHolder method code for WebView is

final VHItem vhItem = (VHItem) holder;

vhItem.webViewChild.getSettings().setUseWideViewPort(false);
vhItem.webViewChild.getSettings().setJavaScriptEnabled(true);

vhItem.webViewChild.loadData("<body>" + html + "</body>", "text/html;charset=utf-8", "utf-8");

where

html is the html string

Update

They have fixed the issue. If you are still having the same problem try updating your Android chrome version to 61 or above.

4 Answers

I solved this problem by floating a WebView in a up layer of RecyclerView, meanwhile placing a HOLDER view in RecyclerView. And then I register an listener to the scroll event of RecyclerView. I Control the position and visibility of the floating WebView

You can try this code in onCreateViewHolder

ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        WebView web = new WebView(parent.getContext());
                        web.setLayoutParams(lp);
                        String url="...";
                        WebSettings settings = web.getSettings();
                        settings.setJavaScriptEnabled(true);
                        settings.setDomStorageEnabled(true);

                        web.loadUrl(url);
                        holder = new ViewHolder(web);
Related