我想在我的 Android 应用程序中通过网络视图显示一个 twitter 小部件。我生成了一个小部件并对其进行了一些自定义
<div style='padding-left: 100px;'><a class="twitter-timeline"
href="http://twitter.com/%s"
data-widget-id="<number>"
data-screen-name="%s"
data-chrome="nofooter noborders noheader transparent"
data-related="benward,endform">
<FONT COLOR="FFFFFF">Tweets by @%s</a>
<script>
!function(d,s,id)
{
var js,fjs=d.getElementsByTagName(s)[0],
p=/^http:/.test(d.location)?'http':'https';
if(!d.getElementById(id))
{
js=d.createElement(s);
js.id=id;
js.src=p+"://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);
}
}(document,"script","twitter-wjs");</script>
我以编程方式从资产加载它:
WebView webView = (WebView) view.findViewById(R.id.webview);
webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
webView.getSettings().setJavaScriptEnabled(true);
webView.setBackgroundColor(Color.BLACK);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e(IrisDelegate.TAG, description);
}
});
try {
StringBuilder builder = new StringBuilder();
InputStream is = getActivity().getAssets().open("twitter.html");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = "";
while ((line = reader.readLine()) != null) {
builder.append(line);
}
String twitter = getArguments().getString(TWITTER);
String data = String.format(builder.toString(), twitter, twitter, twitter);
webView.loadData(data, "text/html", HTTP.UTF_8);
但不幸的是,它不起作用,我只看到指向我的 Twitter 用户页面的链接。你知道问题出在哪里吗?