hide Built In Zoom Controls in WebView - Android android.webkit

Android examples for android.webkit:WebView

Description

hide Built In Zoom Controls in WebView

Demo Code

import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ZoomButtonsController;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Main{

    public static void hideBuiltInZoomControls(WebView view) {
        try {//from w w  w  .  j a va2  s  .  c  o  m
            if (android.os.Build.VERSION.SDK_INT < 11) {
                Field field = WebView.class
                        .getDeclaredField("mZoomButtonsController");
                field.setAccessible(true);
                ZoomButtonsController zoomCtrl = new ZoomButtonsController(
                        view);
                zoomCtrl.getZoomControls().setVisibility(View.GONE);
                field.set(view, zoomCtrl);
            } else {
                WebSettings ws = view.getSettings();
                Method method = WebSettings.class.getMethod(
                        "setDisplayZoomControls", boolean.class);
                method.invoke(ws, false);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

Related Tutorials