create WebView for viewing html string - Android User Interface

Android examples for User Interface:WebView

Description

create WebView for viewing html string

Demo Code


//package com.java2s;

import android.content.Context;

import android.webkit.WebView;

public class Main {
    /**/*from  w  w w.ja  va 2  s .  c o m*/
     * @fn public static WebView createHtmlView(Context context,String html)
     * @brief This creates a new WebView object to display the HTML code in string.
     * @param context
     * @param html HTML code to be displayed. This is a string of the code itself, not a link to a file.
     * @return Created WebView object.
     */

    public static WebView createHtmlView(Context context, String html) {
        WebView webview = new WebView(context);
        webview.loadData(html, "text/html", null);
        webview.setPadding(5, 0, 5, 0);
        return webview;
    }
}

Related Tutorials