首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

WebView 暗藏缩放按钮

2013-09-09 
WebView 隐藏缩放按钮//隐藏webview的缩放按钮 适用于3.0和以后public void setZoomControlGoneX(WebSetti

WebView 隐藏缩放按钮
//隐藏webview的缩放按钮 适用于3.0和以后public void setZoomControlGoneX(WebSettings view ,Object[] args){ Class classType = view.getClass(); try { Class[] argsClass = new Class[args.length]; for (int i = 0, j = args.length; i < j; i++) { argsClass[i] = args[i].getClass(); } Method[] ms= classType.getMethods(); for (int i = 0; i < ms.length; i++) { if(ms[i].getName().equals("setDisplayZoomControls")){ try { ms[i].invoke(view, false);} catch (Exception e) {e.printStackTrace();} break; }//Log.e("test", ">>"+ms[i].getName());}}catch (Exception e) {e.printStackTrace();} }//隐藏webview的缩放按钮 适用于3.0以前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(); } } 调用: weView.loadUrl("file:///android_asset/help.html");int sysVersion = Integer.parseInt(VERSION.SDK);if(sysVersion>=11){setZoomControlGoneX(weView.getSettings(),new Object[]{false});}else{setZoomControlGone(weView);}

?

热点排行