[Android development experience] How to Use WebView to load local images and flash screen appears,
Reprinted please indicate the source: http://blog.csdn.net/zhaokaiqiang1992
- The warning problem has appeared again. The following method cannot be solved. The problem is solved first and then supplemented.
- Problem description
- Running Environment
- Solution
Warning, problem again !!! The following methods cannot be solved !!! The first pitfall, solved and then supplemented !!! Problem description
When you use WebView to load a local image, that is, when an HTML code is embedded into the local image address, the image will flash in gray for a short period, and then the image will be displayed normally, the background color of WebView is set to black in xml.
At the same time, when this problem occurs, Log will print the error message: nativeOnDraw failed; clearing to background color.
Running Environment
Nexus5 Android 4.4
Tool T1 Android 4.4
Samsung s5. Android 4.2
Solution
In stackoverflow, it may be because the WebView of version 4.4 does not support hardware acceleration. Then, set it in the Code 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 set the following in the Code:
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Or flashes. Then set the following in Manifest:
<activity android:hardwareAccelerated="false" android:name=".ui.ImageDetailActivity" android:theme="@style/ImageDetailActivityTheme">
Or not. This time has crashed...
Later, I found the following solution and finally stopped flashing!
webView.setBackgroundColor(Color.parseColor("#000000"));