当前位置:首页 > 开发 > 编程语言 > 编程 > 正文

WebView 隐藏缩放按钮

发表于: 2013-08-21   作者:cloklo   来源:转载   浏览:
摘要: //隐藏webview的缩放按钮 适用于3.0和以后 public void setZoomControlGoneX(WebSettings view ,Object[] args){ Class classType = view.getClass(); try { Class[] argsClass = new Class[args.length];
//隐藏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);
		}

 

WebView 隐藏缩放按钮

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号