[英]Android webview - webpage renders in a very broken way
I am trying to load this popular podcast in an Android WebView: 我正在尝试在Android WebView中加载此流行的播客:
http://www.stitcher.com/podcast/entrepreneuronfirecom/entrepreneur-on-fire-tim-ferriss-other-incredible-entrepreneurs http://www.stitcher.com/podcast/entrepreneuronfirecom/entrepreneur-on-fire-tim-ferriss-other-incredible-entrepreneurs
And this is how I render it: 这就是我渲染它的方式:
public class PodcastsActivity extends BaseActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(100);
webview.setWebViewClient(new WebViewClient());
setContentView(webview);
webview.loadUrl("http://www.stitcher.com/podcast/entrepreneuronfirecom/entrepreneur-on-fire-tim-ferriss-other-incredible-entrepreneurs");
And in my manifest I have the activity defined like this: 在清单中,我定义了以下活动:
<activity
android:name="PodcastsActivity"
android:label="Podcasts"
android:hardwareAccelerated="true"/>
But it renders like this: 但是它呈现为:
Is there an extra setting that needs to be set? 是否需要设置其他设置? Or something I am missing?
还是我想念的东西?
Thanks! 谢谢!
I hope you have looked at other answers. 希望您已经查看了其他答案。 Some of the things you may try are:
您可以尝试以下操作:
1) From webview not loading correctly in application question, you may try and enable java script before loading the URL: 1)从webview无法正确加载应用程序问题中,您可以尝试在加载URL之前启用Java脚本:
webview.setInitialScale(1);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
2) As per Android webview not rendering html content correctly question, if your target is higher than 2.3.3 try adding this in your manifest file. 2)按照Android webview无法正确呈现html内容的问题,如果您的目标高于2.3.3,请尝试将其添加到清单文件中。
android:hardwareAccelerated="true"
Update 更新资料
3) Also check that you have following permission in manifest
as direct child to <manifest>
tag: 3)还要检查您是否在
manifest
中将以下权限作为<manifest>
标记的直接子代:
<uses-permission android:name="android.permission.INTERNET" />
Unable to load webpage using WebView in Android 无法在Android中使用WebView加载网页
4) You can try shouldOverrideUrlLoading() method as stated here . 4)您可以尝试按此处所述使用shouldOverrideUrlLoading()方法。
Update 2 : 更新2 :
As you said that it displays correctly on your browser, there is another possibility of using the above method in case when a certain link is clicked within the app, it opens the default browser. 正如您所说的那样,它可以正确显示在浏览器中,如果在应用程序中单击某个链接时,它可能会使用上述方法,从而打开默认浏览器。 I'm not sure if you would want this but it is a possibility.
我不确定您是否要这样做,但这是有可能的。 Something as follows:
如下所示:
webview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
webview.loadUrl("http://www.stitcher.com/podcast/entrepreneuronfirecom/entrepreneur-on-fire-tim-ferriss-other-incredible-entrepreneurs");
Source: WebView link click open default browser 来源: WebView链接单击打开默认浏览器
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.