"Android development experience" using WebView to load local images with a splash screen solution

Source: Internet
Author: User

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

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.