17

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);
bharath
  • 14,283
  • 16
  • 57
  • 95

8 Answers8

30
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");
  }
}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
15

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);
zvzej
  • 6,276
  • 7
  • 33
  • 41
5

Finally my answer is, Its not possible to hide/remove these button's on WebView in Android 2.3.

bharath
  • 14,283
  • 16
  • 57
  • 95
5

If you want to disable only zoom controls use this: webView.getSettings().setDisplayZoomControls(false);

Piotr Badura
  • 1,574
  • 1
  • 13
  • 17
3

Follow this code. It will help you.

Main.java

    WebView wv = (WebView) findViewById(R.id.webview1) ;
    WebSettings webSettings = wv.getSettings();
    webSettings.setBuiltInZoomControls(false);
    wv.loadUrl(url);
code_finder
  • 1,370
  • 2
  • 21
  • 39
3

Just add this line:

webSettings.setDisplayZoomControls(false);
TheOnlyAnil
  • 877
  • 1
  • 15
  • 27
1

zoom buttons can be removed by implementing your own custom webview, and using reflection to get the built in zoom controls and making them invisible for API below 11 (Honeycomb). The code is as thus works for all APIs upto android nougat;

public class CustomWebView extends WebView{

    private ZoomButtonsController zoom_controll = null;

    public CustomWebView(Context context) {
        this(context, null);
    }

    public CustomWebView(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.webViewStyle);
    }

    public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initWebSettings();
    }

    @SuppressLint("NewApi")
    private void initWebSettings() {
        WebSettings webSettings = getSettings();

        webSettings.setSupportZoom(true);
        webSettings.setBuiltInZoomControls(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            webSettings.setAllowContentAccess(true);
            webSettings.setDisplayZoomControls(false);

        } else {
            try {
                Class webview = Class.forName("android.webkit.WebView");
                Method method = webview.getMethod("getZoomButtonsController");
                zoom_controll = (ZoomButtonsController) method.invoke(this, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if(zoom_controll != null)
            zoom_controll.getZoomControls().setVisibility(View.GONE);
        return super.onTouchEvent(event);
    }

}
Ovokerie Ogbeta
  • 503
  • 7
  • 5
0

Here is a solution:

    if (ev.getAction() == MotionEvent.ACTION_DOWN ||
        ev.getAction() == MotionEvent.ACTION_POINTER_DOWN ||
        ev.getAction() == MotionEvent.ACTION_POINTER_1_DOWN ||
        ev.getAction() == MotionEvent.ACTION_POINTER_2_DOWN ||
        ev.getAction() == MotionEvent.ACTION_POINTER_3_DOWN) {
    if (multiTouchZoom && !buttonsZoom) {
        if (ev.getPointerCount() > 1) {
            getSettings().setBuiltInZoomControls(true);
            getSettings().setSupportZoom(true);
        } else {
            getSettings().setBuiltInZoomControls(false);
            getSettings().setSupportZoom(false);
        }
    }
}

if (!multiTouchZoom && buttonsZoom) {
    if (getPointerCount(ev) > 1) {
        return true;
    }
}

In your case multiTouchZoom is true and buttonsZoom is false.

I found it here enable/disable zoom in Android WebView and it's worked for me.

Community
  • 1
  • 1
Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146
  • what are multiTouchZoom and buttonsZoom variables? – jayellos Sep 12 '12 at 12:40
  • @jayellos replace them with your boolean values. If you want multitouch zoom, replace `multiTouchZoom` with true. If you need to display zoom buttons, replace `buttonsZoom` with true. Otherwise, replace with false. – Dmitry Zaytsev Sep 12 '12 at 13:02