有没有办法隐藏和显示在web视图缩放控件? [英] Is there a way to hide and show the zoom controls on a WebView?

查看:201
本文介绍了有没有办法隐藏和显示在web视图缩放控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个意见。一个是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();
    }
}
 

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

这篇关于有没有办法隐藏和显示在web视图缩放控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆