Loading HTML code with WebView

Source: Internet
Author: User

When using EditText to display HTML strings, EditText does not parse any HTML tags, but instead displays all the HTML tags directly-----as if they were displayed in a regular Notepad, or if the application wants to re-parse the HTML string, As an HTML page to display, it is also possible.

WebView provides a loaddata (string data, String MimeType, String encoding) method that can be used to load and display HTML code, but during actual use, when it loads content containing Chinese HTML, the Web The view will display garbled characters.

WebView also provides a loaddatawithbaseurl (string baseUrl, String data, String MimeType, String encoding, String history URL) method, which is an enhanced version of the LoadData (string data, String MimeType, String encoding) method, which does not produce garbled characters.

1. Data: Specifies the HTML code that needs to be loaded.

2. MimeType: Specifies the MIME type of HTML code, which can be specified as text/html for HTML code.

    3, Encoding: Specifies the character set used for HTML code encoding. For example, designated as GBK.

import android.os.bundle;import android.app.activity;import android.view.menu;import   android.webkit.webview;public class viewhtml extends activity {WebView show; @Override protected void oncreate (bundle savedinstancestate)  {super.oncreate (    Savedinstancestate);    Setcontentview (r.layout.activity_view_html);    Gets the WebView component show =  (WebView)  findviewbyid (r.id.show) in the program;    Stringbuilder sb = new stringbuilder ();    Stitching a section of HTML code sb.append ("


This article is from the "Liangxiao Technology Center" blog, please be sure to keep this source http://liangxiao.blog.51cto.com/3626612/1889694

Loading HTML code with 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.