歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android webview 實現放大縮小 隱藏控件問題

Android webview 實現放大縮小 隱藏控件問題

日期:2017/3/1 9:59:44   编辑:Linux編程

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);

通過以上方法即可實現

更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved