Reprint Please specify source: http://blog.csdn.net/zhaokaiqiang1992
-
- Problem description
- Operating Environment
- Solution Solutions
Problem description
When using WebView to load local images, which is a piece of HTML code embedded in the local image address form, there will be a brief gray flicker, and then the normal display of the picture, WebView background color in the XML is set to black.
At the same time, when this problem occurs, log will print error message: Nativeondraw failed; Clearing to background color.
Operating Environment
NEXUS5 Android 4.4
Hammer T1 Android 4.4
Samsung S5 Android 4.2
Solution Solutions
From StackOverflow, it is possible that the 4.4 version of WebView does not support hardware acceleration, and then the code is set up as follows:
<WebView android:id="@+id/web_gif" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none" android:layerType="software" />
does not work, and then the code is set up as follows:
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
or flashes are present. And then set the following in manifest
<activity android:hardwareAccelerated="false" android:name=".ui.ImageDetailActivity" android:theme="@style/ImageDetailActivityTheme">
It's still not working. This time has collapsed ...
Later found the following solution, finally no longer flashing!
webView.setBackgroundColor(Color.parseColor("#000000"));
"Android development experience" using WebView to load local images with a splash screen solution