【发布时间】:2015-05-08 10:39:27
【问题描述】:
我有一个 HTML5 网络应用,我想创建一个 Android 应用。
我做的第一件事是打开 Visual Studio 并使用 webview 制作一个简单的应用程序。在这种情况下,我可以配置我的 webview 的缩放选项。
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setDisplayZoomControls(false);
一切正常。
然后我想创建相同的应用程序 usig cordova。该应用程序运行良好,但我无法进行缩放,而且我无法配置 Cordova Webview...我尝试自定义 Main Activity,但我不知道如何访问 Cordova Webview 的设置
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
WebSettings settings = this.appView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setBuiltInZoomControls(true);
有什么想法吗?谢谢。
编辑 1
你的回答我得到这个错误:
C:\Users\xabier.esteban\Datavis\cordova\hello\platforms\android\src\com\example\
hello\MainActivity.java:35: error: cannot find symbol
WebSettings settings = super.appView.getSettings();
^
symbol: method getSettings()
location: variable appView of type CordovaWebView
1 error
:compileDebugJava FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
BUILD FAILED
Total time: 3.321 secs
【问题讨论】:
-
我也遇到了同样的问题,无法在带有cordova的Android中启用捏缩放(使用cordova 4.0)。尝试了元视口标签的所有变体。我清楚地记得 Android 通过将 WebSettings 代码添加到 MainActivity.java 来放大以前的 cordova 版本,但 getSettings() 方法似乎已经从 CordovaWebView 中消失了。希望有任何解决方法。
-
crosswalk-project.org/jira/browse/XWALK-3313 : "我们引入
preference API替换getSettings。我们需要记录这个新API 并帮助开发人员从 getSettings 迁移”。由于我还没有找到那个 API 的文档,所以这个评论(而不是答案)必须要做,至少现在你知道要搜索什么了..
标签: android cordova webview android-webview