WebView “flashing” with white background if hardware acceleration is enabled (Android 3.0+)

前端 未结 6 1452
再見小時候
再見小時候 2020-12-13 05:53

I have an issue with the WebView (Android 3.0+), which the WebView always displays a white background before display my black background (\"flashing\"). Here is my simple te

6条回答
  •  佛祖请我去吃肉
    2020-12-13 06:35

    I found the most effective fix for this, first mentioned here, was to set a transparent background color after the layout has been inflated:

    webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
    

    Yes, it's a total hack, but it's the only solution I've found to work well without disabling hardware acceleration.

    Note that this does not work through setting the background in XML.

    This has been resolved in Jellybean, although some users have reported seeing this in KitKat. Check that you have not disabled hardware acceleration, and if the problem indeed disappears, you will probably want to wrap that code in a conditional statement to only target older devices:

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
    }
    

提交回复
热议问题