【问题标题】:NativeScript: How do I disable zoom controls in WebView?NativeScript:如何禁用 WebView 中的缩放控件?
【发布时间】:2016-04-23 07:42:53
【问题描述】:

我从以下问题中找到了在 Android WebView 中启用/禁用缩放控件的方法。

How to remove zoom buttons on Android webview?

我正在使用 NativeScript,但在 NativeScript WebView 中没有看到类似的方法。有什么方法可以从 NativeScript 访问 Android WebView 的方法吗?或者,还有其他方法吗?

谢谢。

【问题讨论】:

    标签: webview nativescript


    【解决方案1】:

    您可以通过 WebView 的 android 属性获取实际的 android。所以你可能可以在加载的事件中使用类似的东西:

    var webView = page.getViewById("webViewID");
    if(webView.android) { // in IOS android will be undefined
      webView.android.getSettings().setBuiltInZoomControls(false);
    }
    

    【讨论】:

    • 我之前尝试过,但没有成功。我虽然做错了,你的回答鼓励我再试一次。现在,在将该代码放入 WebView 的 loadStarted 事件后,它就可以工作了。谢谢。
    • 但是我怎样才能获得角度的页面参考
    • 如何在保持捏合缩放功能的同时仅隐藏按钮?
    • 有人知道我如何在 {N}-Vue 中获得page 吗?原来ReferenceError: page is not defined
    【解决方案2】:

    只需将此元标记添加到您的 html 的标题

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
    

    【讨论】:

      【解决方案3】:

      在 NS + Angular 中:

      import { WebView, LoadEventData } from "ui/web-view";
      ...
      //Get the element ref from the view #webView
      @ViewChild("webView") webView: ElementRef;  
      ...
      //Get the real object type casted
      let webview: WebView = this.webView.nativeElement; 
      if(webview.android) {
          webview.android.getSettings().setBuiltInZoomControls(false);
      }
      

      【讨论】:

        猜你喜欢
        • 2018-07-27
        • 2011-10-30
        • 1970-01-01
        • 1970-01-01
        • 2011-12-24
        • 2011-06-28
        • 2015-01-14
        • 2015-05-07
        • 2014-01-23
        相关资源
        最近更新 更多