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