微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WebView中的Android 1按钮

我已经尝试使用他们描述的方法在GoogleView中放置Google的1个按钮.我已经初始化了WebView,如下所示:

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代码

<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone href="https://stackoverflow.com"></g:plusone>

问题是……按钮根本不显示.

我如何解决它?顺便说一句 – 我也希望按钮能够使用WebView启动新窗口.有简单的解决方案吗?

谢谢

解决方法:

问题在于WebView中的权限系统.本地文件中的脚本在访问外部资源时遇到问题.解决方案是让WebView认为本地代码是从外部网站加载的.

web.loadDataWithBaseURL("http://fake.com", htmlCodeGoesHere, "text/html", "utf-8", null);

该按钮将出现,但不幸的是它在WebView中不能正常工作.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐