[Android development experience] How to Use WebView to load local images and flash screen appears,

Source: Internet
Author: User

[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"));

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.