问题描述
在我的应用程序,我想通过web视图显示在我的网站的评论。这是我做了什么:
In my app, I would like to show comments in my website by webview.This is what I have done:
在资产文件夹中我有一个名为comment.html文件
In assets folder I have got a file named comment.html
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "http://connect.facebook.net/en_US/all.js#xfbml=1&appId=467390796664437";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="http://www.haivl.com/photo/1259735" data-width="470"></div>
</body>
</html>
-
在CommentViewActivity.java
In CommentViewActivity.java
公共类CommentViewActivity延伸活动{ 公共静态上下文的背景下; 私人的WebView web视图;
public class CommentViewActivity extends Activity { public static Context context; private WebView webView;
@SuppressLint("SetJavaScriptEnabled") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_zini_login); context = this; CookieSyncManager.createInstance(this); CookieManager cm = CookieManager.getInstance(); cm.removeAllCookie(); webView = (WebView) findViewById(R.id.web_login); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("file:///android_asset/comment.html"); webView.setWebViewClient(new WebViewClientActivity()); } public class WebViewClientActivity extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { System.out.println("onPageStarted: " + url); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onPageFinished(WebView webView, String url) { System.out.println("onPageFinished: " + url); } }
}
活动显示如下:
The activity displays as follow:
正如你所看到的,Facebook的评论框遮挡而看不到整个评论。任何人有一个想法?
As you can see, the facebook comment box obscured and I can't see whole comments.Anyone has a idea?
感谢您的关注!
推荐答案
基础上,这个帖子Failed通过本地HTML 呈现在Android的WebView Facebook的评论?
base on this post Failed to render Facebook comments on Android WebView via local HTML?
您需要指定一个基本URL。
You need to specify a base URL.
myWebView.loadDataWithBaseURL("http://www.haivl.com", "<html> <head> </head> <body> <div id="fb-root"></div> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "http://connect.facebook.net/en_US/all.js#xfbml=1&appId=467390796664437"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <div class="fb-comments" data-href="http://www.haivl.com/photo/1259735" data-width="470"></div> </body> </html>", "text/html", null, null);
这篇关于在Android的Facebook的评论框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!