Android: Disable WebView zoom controls

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+.

/**
* Disable zoom buttons for WebView.
*/
public static void disableWebviewZoomControls(final WebView webview) {
webview.getSettings().setSupportZoom(true);
webview.getSettings().setBuiltInZoomControls(true);

// Use the API 11+ calls to disable the controls
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
new Runnable() {
@SuppressLint("NewApi")
public void run() {
webview.getSettings().setDisplayZoomControls(false);
}
}.run();
}
else {
try {
ZoomButtonsController zoom_control;
zoom_control = ((ZoomButtonsController) webview.getClass().getMethod("getZoomButtonsController").invoke(webview, (Object[]) null));
zoom_control.getContainer().setVisibility(View.GONE);
}
catch (Exception e) {
e.printStackTrace();
}
}
}

Source

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