有没有办法隐藏和显示在web视图缩放控件?缩放、没有办法、视图、控件

2023-09-07 04:56:13 作者:小猪嘟嘟

我有两个意见。一个是web视图,而另一个是一个ImageView的。我设置自动缩放控件像这样的WebView:

  webview.getSettings()setBuiltInZoomControls(真)。
 

我只是改变这两种观点的知名度使用 GONE 可见。当改变我的观点,从的WebView到的ImageView,缩放控件不会失去自己的知名度一段时间。

有没有隐藏和显示的Autozoomcontrols任何可能的方式?

编辑:

我尝试了这些方法,但它仍然没有工作。

  webview.getZoomControls()setVisibility(View.GONE)。
。webview.getZoomControls()无效();
 

解决方案

 公共无效setZoomControlGone(查看视图){
    类<> classType所;
    场场;
    尝试 {
        classType所= WebView.class;
        字段= classType.getDeclaredField(mZoomButtonsController);
        field.setAccessible(真正的);
        ZoomButtonsController mZoomButtonsController =新ZoomButtonsController(视图);
        mZoomButtonsController.getZoomControls()setVisibility(View.GONE)。
        尝试 {
            field.set(查看,mZoomButtonsController);
        }赶上(抛出:IllegalArgumentException E){
            e.printStackTrace();
        }赶上(IllegalAccessException E){
            e.printStackTrace();
        }
    }赶上(SecurityException异常E){
        e.printStackTrace();
    }赶上(NoSuchFieldException E){
        e.printStackTrace();
    }
}
 
Web 隐藏技术 几中隐藏 Web 中的元素方法及优缺点 前端小智 CSDN博客 页面隐藏的方式和优缺点

I have a two Views. One is a WebView and the other is an ImageView. I set the auto zoom controls for the WebView like so:

webview.getSettings().setBuiltInZoomControls(true);

I am just changing the visibility of both Views using GONE and Visible. While changing my View from WebView to ImageView, the zoom controls do not lose their visibility for some period of time.

Is there any possible way to hide and show the Autozoomcontrols?

Edit:

I tried these methods, but it's still not working.

webview.getZoomControls().setVisibility(View.GONE);
webview.getZoomControls().invalidate();

解决方案

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