Set transparent background color for android webview

Source: Internet
Author: User
Tags transparent image

Android WebView sets the background color to transparent

I have tried a lot of methods on the Internet.

1. Set the background to transparent or transparent image (invalid)


[Html]
Android: background = "@ android: color/transparent"

Android: background = "@ android: color/transparent"
2. Set the loaded html as a transparent background image (invalid)


[Java]
String mobileDetails = ""<Div style = 'background-image: url (file: // android_asset/z_bg_transparent.png); '>" +
MGetDetail. data. get ("description ")
+ "</Div>

String mobileDetails = ""<Div style = 'background-image: url (file: // android_asset/z_bg_transparent.png); '>" +
MGetDetail. data. get ("description ")
+ "</Div> 3. The so-called online (invalid)


[Html]
Android: layerType = "software"

Android: layerType = "software"
Or


[Html]
Android: hardwareAccelerated = "false"

Android: hardwareAccelerated = "false"
4. Set mWebView. setBackgroundColor (0) directly in the Code; (invalid)

5. Finally, I grabbed my scalp and set the transparency of mWebView. setBackgroundColor (0). Based on this, the result is OK (valid)

The Code is as follows:


[Java]
MWebView. getSettings (). setJavaScriptEnabled (true );
MWebView. getSettings (). setDefaultTextEncodingName ("UTF-8 ");
MWebView. setBackgroundColor (0); // sets the background color.
MWebView. getBackground (). setAlpha (0); // set the fill transparency range: 0-255
MWebView. loadDataWithBaseURL (null, "loading .. "," Text/html "," UTF-8 ", null );
MWebView. loadDataWithBaseURL (mGetDetail. data. get ("hostsUrl"), mGetDetail. data. get ("description"), "text/html", "UTF-8", null );
MWebView. setVisibility (View. VISIBLE); // set and display after loading to avoid poor initialization performance during loading

MWebView. getSettings (). setJavaScriptEnabled (true );
MWebView. getSettings (). setDefaultTextEncodingName ("UTF-8 ");
MWebView. setBackgroundColor (0); // sets the background color.
MWebView. getBackground (). setAlpha (0); // set the fill transparency range: 0-255
MWebView. loadDataWithBaseURL (null, "loading .. "," Text/html "," UTF-8 ", null );
MWebView. loadDataWithBaseURL (mGetDetail. data. get ("hostsUrl"), mGetDetail. data. get ("description"), "text/html", "UTF-8", null );
MWebView. setVisibility (View. VISIBLE); // set and display after loading to avoid poor initialization performance during loading

 


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.