/** 实现放大缩小控件隐藏 */
  public static void setZoomControlGone(WebView view) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // 用于判断是否为Android 3.0系统, 然后隐藏缩放控件
      view.getSettings().setDisplayZoomControls(false);
    } else {

      // Android 3.0(11) 以下使用以下方法:
      // 利用java的反射机制

      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();
      }
    }
  }
Пример #2
0
 void updateZoomControls() {
   if (mZoomButtonsController == null) return;
   boolean canZoomIn = mContentViewCore.canZoomIn();
   boolean canZoomOut = mContentViewCore.canZoomOut();
   if (!canZoomIn && !canZoomOut) {
     // Hide the zoom in and out buttons if the page cannot zoom
     mZoomButtonsController.getZoomControls().setVisibility(View.GONE);
   } else {
     // Set each one individually, as a page may be able to zoom in or out
     mZoomButtonsController.setZoomInEnabled(canZoomIn);
     mZoomButtonsController.setZoomOutEnabled(canZoomOut);
   }
 }
Пример #3
0
 private ZoomButtonsController getControls() {
   if (mZoomButtonsController == null) {
     mZoomButtonsController = new ZoomButtonsController(mWebView.getWebView());
     mZoomButtonsController.setOnZoomListener(new ZoomListener());
     // ZoomButtonsController positions the buttons at the bottom, but in
     // the middle. Change their layout parameters so they appear on the
     // right.
     View controls = mZoomButtonsController.getZoomControls();
     ViewGroup.LayoutParams params = controls.getLayoutParams();
     if (params instanceof FrameLayout.LayoutParams) {
       ((FrameLayout.LayoutParams) params).gravity = Gravity.RIGHT;
     }
   }
   return mZoomButtonsController;
 }
Пример #4
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();
   }
 }
Пример #5
0
 // This method is used in tests. It doesn't modify the state of zoom controls.
 View getZoomControlsViewForTest() {
   return mZoomButtonsController != null ? mZoomButtonsController.getZoomControls() : null;
 }