android webview为我们提供了很多方便的接口及方法,在使用其放大和缩小功能时也一样的如此方便,但有一个问题就是在使用的时候很容易跟webview控件中的内容形成操作上的冲突,最后通过网上查找资料实现了放大缩小功能,主要分为两步具体如下
//实现放大缩小控件隐藏 public void setZoomControlGone(View view) { Class classType; Field field; try { classType = WebView.class; field = classType.getDeclaredField("mZoomButtonsController"); field.setAccessible(true); ZoomButtonsController mZoomButtonsController = new ZoomButtonsController(view); mZoomButtonsController.getZoomControls().setVisibility(View.GONE); try { field.set(view, mZoomButtonsController); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } }
调用:
webView = (WebView) findViewById(R.id.webView); webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); WebSettings webSettings =webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); setZoomControlGone(webView);