Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove zoom buttons on Android webview?

Is it possible to remove the zoom buttons enter image description here? Its showing when I zooming the WebView. I need zoom control without these buttons. I'm using android 2.3.

I used below code,

WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setBuiltInZoomControls(false);
webview.getSettings().setJavaScriptEnabled(true);
FrameLayout mContentView = (FrameLayout) getWindow().
        getDecorView().findViewById(android.R.id.content);
final View zoom = webview.getZoomControls();
mContentView.addView(zoom, ZOOM_PARAMS);
zoom.setVisibility(View.GONE);
like image 986
bharath Avatar asked May 26 '12 13:05

bharath


People also ask

What is zoom control in Android?

In Android, Zoom Control is a class that has some set of methods that are used to control the zoom functionality. It has two buttons that are used to control the zoom functionality (ie Zoom In and Zoom Out). Zoom Control Class has been deprecated in API Version 29.


2 Answers

getSettings().setBuiltInZoomControls(false);

use the above line of code to remove the zoom buttons.

On API >= 11, you can use:

webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);

Updated::: If you want have zoom in/out without zoom controls then use the below code(copied from here)

public class Main extends Activity {
  private WebView myWebView;
  private static final FrameLayout.LayoutParams ZOOM_PARAMS =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM);

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);
    myWebView = (WebView)findViewById(R.id.webView);

    FrameLayout mContentView = (FrameLayout) getWindow().
    getDecorView().findViewById(android.R.id.content);
    final View zoom = myWebView.getZoomControls();
    mContentView.addView(zoom, ZOOM_PARAMS);
    zoom.setVisibility(View.GONE);

    myWebView.loadUrl("http://www.almondmendoza.com");
  }
}
like image 185
Shankar Agarwal Avatar answered Nov 17 '22 12:11

Shankar Agarwal


Change this on your AndroidManifest:

    android:minSdkVersion="8"

to this:

    android:minSdkVersion="11"

than use this in your web view settings:

getSettings().setBuiltInZoomControls(true);
    getSettings().setDisplayZoomControls(false);
like image 31
zvzej Avatar answered Nov 17 '22 13:11

zvzej