load Local Url to WebView - Android User Interface

Android examples for User Interface:WebView URL

Description

load Local Url to WebView

Demo Code


//package com.java2s;

import android.graphics.Paint;

import android.os.Build;

import android.view.View;

import android.webkit.WebView;

import java.lang.reflect.Method;

public class Main {
    public static void loadLocalUrl(WebView webView, String urlBasePath,
            String htmlContent, boolean zoom) {
        webView.getSettings().setSupportZoom(zoom);
        webView.loadDataWithBaseURL(urlBasePath, htmlContent, "text/html",
                "utf-8", null);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            try {
                final Method method = View.class.getMethod("setLayerType",
                        int.class, Paint.class);
                method.invoke(webView, 1, new Paint());
            } catch (final Exception e) {
                e.printStackTrace();//from w w  w  . j  a  v  a 2  s.c  o  m
            }
        }
    }
}

Related Tutorials