我试图把使用它们所描述的方法的WebView谷歌的+1按钮。我已经初始化的WebView如下:
I've tried putting Google's +1 button in WebView using the methods they describe. I've initialized the WebView as follows:
final WebView web = (WebView)findViewById(R.id.webView);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setSavePassword(false);
web.getSettings().setBuiltInZoomControls(false);
web.getSettings().setUseWideViewPort(true);
web.getSettings().setLoadWithOverviewMode(true);
web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
web.setHorizontalScrollBarEnabled(false);
web.setBackgroundColor(0xff2e2e2e);
web.loadDataWithBaseURL(null, htmlCodeGoesHere, "text/html", "utf-8", null);
和HTML code:
And the html code:
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone href="http://stackoverflow.com"></g:plusone>
问题是...按钮不会显示在所有。
The problem is... the button doesn't display at all.
如何解决呢?顺便说一句 - 我也希望按钮来启动一个新的窗口,而是使用web视图。有没有一个简单的解决方案?
How do I fix it? By the way - I also want the button to launch a new window instead using the WebView. Is there a simple solution?
感谢
问题在于权限系统的WebView。在本地文件脚本有访问外部的资源问题。解决的办法是使的WebView认为当地code从外部网站加载。
The problem lies in permissions system in WebView. Scripts in local files have problems accessing external resources. The solution is to make WebView think local code was loaded from external website.
web.loadDataWithBaseURL("http://fake.com", htmlCodeGoesHere, "text/html", "utf-8", null);
的按钮,会出现,但是unfortunetely它不能在web视图很好地工作。
The button will appear, but unfortunetely it doesn't work well in WebView.
上一篇:单选按钮在 Chrome 中显示不需要的白色背景.火狐没问题不需要、火狐、单选、按钮
下一篇:FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS排除整个应用程序,不仅活动应用程序、FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS