Garbled problems with Android WebView

Source: Internet
Author: User

1, webview load webpage

1, Webview.loadurl (); Directly display the content of the Web page (display the network picture separately), usually does not appear garbled. 2, Webview.loaddata (data,  "text/html",  "UTF-8"); LoadData is primarily designed to load data in URI format, and it cannot load content over the network. Online WebView loaded Chinese garbled, mostly using this method. There are two main problems in using the process: (1) loaddata cannot load picture content, and if you want to load the picture content or get more powerful web support, it is recommended to use a more powerful loaddatawithbaseurl. (2)   Many practical loaddata methods of friends have encountered the problem of garbled display, that is due to incorrect encoder settings. We know that the string type of data is mainly Unicode encoding, and webview generally to save resources using UTF-8 encoding, so we have to tell the method how to Transcode when LoadData. That is to tell it to turn Unicode encoded content into UTF-8 encoded content. Some friends, although the encoding method in the LoadData, but still garbled, this is because the text encoding of WebView also need to specify the encoding. For example, the following:webview wv =  (WebView) Findviewbyid (R.id.webview)  ;wv.getsettings (). Setdefaulttextencodingname ("Utf -8")  ;wv.loaddata (content,  "text/html",  "UTF-8")  ; Note for gb2312 or GBK (3). Page description encoding format  <meta http-equiv= "Content-type"  content= "text/html;charset=gb2312" > above two methods are online to give a better method, but I have not tried to solve my garbled problem.   Originally I used LoadData method to parse HTML, but it is said that this is an official bug, can not be used to parse Chinese. So go around its path, using Loaddatawithbaseurl method, where Codeingtype is set to Utf-8 OK. 3, where BaseURL for you to store the path of the photos, such as:

2, webview background transparent:

Setting android:background in the XML file is not valid.

<webview

Android:id= "@+id/big_data_detail_content_textview"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

Android:textcolor= "#fff"

android:background= "@drawable/color_transparent"

Android:textsize= "14DP"/>

Workaround:

Webview.setbackgroundcolor (0); Set Background transparency


Garbled problems with Android WebView

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.