Android: Disable WebView zoom controls

0 Comments

This method doesn't require you to subclass the WebView, which makes life a bit easier for everyone involved.

The best part is that it works with all versions from 1.6+.

01./**
02. * Disable zoom buttons for WebView.
03. */
04.public static void disableWebviewZoomControls(final WebView webview) {
05.  webview.getSettings().setSupportZoom(true);
06.  webview.getSettings().setBuiltInZoomControls(true);
07. 
08.  // Use the API 11+ calls to disable the controls
09.  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
10.    new Runnable() {
11.      @SuppressLint("NewApi")
12.      public void run() {
13.        webview.getSettings().setDisplayZoomControls(false);
14.      }
15.    }.run();
16.  }
17.  else {
18.    try {
19.      ZoomButtonsController zoom_control;
20.      zoom_control = ((ZoomButtonsController) webview.getClass().getMethod("getZoomButtonsController").invoke(webview, (Object[]) null));
21.      zoom_control.getContainer().setVisibility(View.GONE);
22.    }
23.    catch (Exception e) {
24.      e.printStackTrace();
25.    }
26.  }
27.}

Source

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog