14

I'm interested in determining what the optimal settings are for a WebView that is intended to show HTML5 content.

Currently I'm using :

mWebView.setFocusable(true);
mWebView.setFocusableInTouchMode(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

With these settings, the WebView score 189 (w/ 1 bonus) on html5test.com. I am wondering if there are any settings that I should/could change to get further compatibility with HTML5. Of course, this list is an amalgamation of settings compiled over some months, so I'm also open to being told I'm doing something wrong. I do not have control over the html content to be displayed but am trying to support as broad a swath of HTML5 as possible.

4

4 回答 4

7

我要补充:

    mWebView.setWebViewClient(new WebViewClient()); // tells page not to open links in android browser and instead open them in this webview
于 2012-05-11T14:25:36.460 回答
3

这是一个与最佳 HTML5 设置有关的(较旧的)项目:
http ://code.google.com/p/html5webview/source/browse/trunk/HTML5WebView/src/org/itri/html5webview/HTML5WebView.java

仅供参考,通常我还会为 HTML5 设置数据库存储路径:

mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setDatabasePath("/data/data/" + Actvity.getPackageName() + "/databases/");
于 2012-04-11T02:47:08.133 回答
2

也可以设置为

try {
  WebSettings settings = view.getSettings();
      settings.setJavaScriptCanOpenWindowsAutomatically(true);
      settings.setSupportMultipleWindows(true);
      settings.setBuiltInZoomControls(true);
      settings.setJavaScriptEnabled(true);
      settings.setAppCacheEnabled(true);
      settings.setAppCacheMaxSize(10 * 1024 * 1024);
      settings.setAppCachePath("");
      settings.setDatabaseEnabled(true);
      settings.setDomStorageEnabled(true);
      settings.setGeolocationEnabled(true);
      settings.setSaveFormData(false);
      settings.setSavePassword(false);
      settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
      // Flash settings
      settings.setPluginState(WebSettings.PluginState.ON);

      // Geo location settings
      settings.setGeolocationEnabled(true);
      settings.setGeolocationDatabasePath("/data/data/selendroid");
    } catch (Exception e) {
      SelendroidLogger.error("Error configuring web view", e);
    }
于 2018-04-26T06:24:52.193 回答
1

恕我直言,答案可能比您的 Android 版本更多,而不是特定设置。

看看 CanIUse.com 的“表格”部分:

... 或 MobileHTML5.org:

于 2012-04-10T22:23:43.073 回答