5
votes

I have the following problem: I am loading a html file into a webview. The background color of my html file and my activity is black. What happens is that there is a short white flash at the beginning when finished loading because the background color of the webview is white.

Can I remove that flash? Or set that webview color to black? I already tried setting the background color in the webview xml to black, but it didn't work.

3

3 Answers

5
votes

Yes you can. Try:

webview.setBackgroundResource(Color.Black);
2
votes

I had the same problem and this solved it for me:

Just below the existing

mWebView = (WebView) findViewById(R.id.activity_main_webview);

I added the line

mWebView.setBackgroundColor(Color.BLACK);

To do any good it must be before

mWebView.loadUrl(...)
0
votes

setting background (xml or programmatically) didn't work for me, just use CustomTabs it's faster so this issue didn't seem to matter. Especially if you use the optimizations (warmup and mayLaunchUrl) detailed here: https://www.captechconsulting.com/blogs/an-introduction-to-chrome-custom-tabs-for-android