Cocos Creator 嵌在webview运行黑屏问题。

前端之家收集整理的这篇文章主要介绍了Cocos Creator 嵌在webview运行黑屏问题。前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用Cocos Creator 嵌在webview运行有时会出现黑屏问题, 但是并不是所有app都黑屏, 这类问题就需要app检查一下给webview提供的权限了, 我之前遇到黑屏就是因为用到了localStorage, 而webview没有开启, 需要java端设置一下:webSettings.setDomStorageEnabled(true);


WebSettings用来对WebView的配置进行配置和管理,比如是否可以进行文件操作、缓存的设置、页面是否支持放大和缩小、是否允许使用数据库api、字体及文字编码设置、是否允许js脚本运行、是否允许图片自动加载、是否允许数据及密码保存等等
示例代码如下:

[java] view plain copy

在CODE上查看代码片

派生到我的代码片

  1. WebSettingswebSettings=mWebView.getSettings();
  2. webSettings.setJavaScriptEnabled(true);
  3. webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
  4. webSettings.setDomStorageEnabled(true);
  5. webSettings.setDatabaseEnabled( webSettings.setAppCacheEnabled(true);
  6. webSettings.setAllowFileAccess( webSettings.setSavePassword( webSettings.setSupportZoom( webSettings.setBuiltInZoomControls(
  7. webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
  8. webSettings.setUseWideViewPort(
  9. mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
  10. mWebView.setHorizontalScrollbarOverlay( mWebView.setHorizontalScrollBarEnabled( mWebView.requestFocus();

相关权限请参考:http://blog.sina.com.cn/s/blog_61cf99580102vj36.html

原文链接:https://www.f2er.com/cocos2dx/338468.html

猜你在找的Cocos2d-x相关文章