Is there a way to hide and show zoom controls in a WebView?

I have two views. One is WebView and the other is ImageView. I set the auto-scaling elements for WebView as follows:

webview.getSettings().setBuiltInZoomControls(true); 

I just change the visibility of both views using GONE and Visible . When you change my view from WebView to ImageView, the zoom controls do not lose their visibility for a period of time.

Is there any possible way to hide and show Autozoomcontrols?

Edit:

I tried these methods, but it still does not work.

 webview.getZoomControls().setVisibility(View.GONE); webview.getZoomControls().invalidate(); 
+6
android webview zoom
source share
3 answers
 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(); } } 
+3
source share

You can get the view you get from WebView.getZoomControls () and add it as a child to the layout next to (or on top of) the webview. Unfortunately this is hacked, getZoomControls is deprecated, and you won’t get a pinch of zoom unless you call WebSettings.setBuildInZoomControls (true) (which will add the SECOND zoom controls view that you don't need), but it seems to work. Here is my code to do this for what it stands:

Xml layout:

 <RelativeLayout android:id="@+id/rl" android:layout_width="fill_parent" android:layout_height="fill_parent"> <WebView android:id="@+id/wv" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <FrameLayout android:id="@+id/wv_zoom_fl" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" /> </RelativeLayout> 

Java (inside the action):

 WebView wv = (WebView)findViewById(R.id.wv); FrameLayout zoomfl = (FrameLayout)findViewById(R.id.wv_zoom_fl); zoomfl.removeAllViews(); zoomfl.addView(wv.getZoomControls()); 

Now, to zoom out, you can set the visibility of R.id.rl (which contains the WebView and FrameLayout containing the zoom controls) to RelativeLayout.GONE.

For a disappointing solution: if your minimum Api is set to level 11 (which is Honeycomb 3.0, unfortunately, this is unlikely), you can use: http://developer.android.com/reference/android/webkit/WebSettings.html#setDisplayZoomControls (boolean)

0
source share

I guess this will work.

 webView.getSettings().setUseWideViewPort(true); 
-3
source share

All Articles