set Zoom Control Gone for WebView - Android User Interface

Android examples for User Interface:WebView Zoom

Description

set Zoom Control Gone for WebView

Demo Code


//package com.java2s;

import android.os.Build;

import android.view.View;

import android.webkit.WebView;

import android.widget.ZoomButtonsController;
import java.lang.reflect.Field;

public class Main {

    public static void setZoomControlGone(WebView view) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            view.getSettings().setDisplayZoomControls(false);
        } else {/*  ww  w.  j av  a 2s  .  c o m*/
            Class classType;
            Field field;
            try {
                classType = WebView.class;
                field = classType
                        .getDeclaredField("mZoomButtonsController");
                field.setAccessible(true);
                ZoomButtonsController mZoomButtonsController = new ZoomButtonsController(
                        view);
                mZoomButtonsController.getZoomControls().setVisibility(
                        View.GONE);
                try {
                    field.set(view, mZoomButtonsController);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
        }
    }
}

Related Tutorials