android webview為我們提供了很多方便的接口及方法,在使用其放大和縮小功能時也一樣的如此方便,但有一個問題就是在使用的時候很容易跟webview控件中的內容形成操作上的沖突,最後通過網上查找資料實現了放大縮小功能,主要分為兩步具體如下
[java]
//實現放大縮小控件隱藏
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();
}
}
調用:
[java]
webView = (WebView) findViewById(R.id.webView);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
WebSettings webSettings =webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
setZoomControlGone(webView);