在web视图Android的+1按钮 [英] Android +1 button in WebView

查看:216
本文介绍了在web视图Android的+1按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把使用它们所描述的方法的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.

这篇关于在web视图Android的+1按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆