Android的WebView中不能正确显示网页 [英] Android WebView does not display web page correctly

查看:386
本文介绍了Android的WebView中不能正确显示网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的WebView code是这样的:

I have simple WebView code like this:

WebView wv = (WebView) findViewById(R.id.webview1);                  

        wv.loadUrl("http://en.wikipedia.org/wiki/Book");  

但显示的页面显示维基百科的内容一样,如果它是桌面浏览器看起来pretty手机难看。如果我使用浏览器的应用程序去维基百科网站我的手机上,然后将它正确地按手机布局显示的内容。

But the displayed page shows wikipedia content like as if it was desktop browser which looks pretty ugly on a mobile phone. If I go to wikipedia website on my mobile phone using the browser application, then it displays content correctly according to mobile phone layout.

我试着设置用户代理字符串中的WebView但这并没有帮助。

I tried setting user agent string in webview but that does not help either.

没有任何一个有这个解决方案?

Does any one has solution for this?

推荐答案

许多网站使用JavaScript的浏览器检测。您需要启用JavaScript,请的WebView。这对我的作品:

Many sites use JavaScript for browser detection. You need to enable JavaScript for your webview. This works for me:

WebView wv = (WebView) findViewById(R.id.webview1);
wv.getSettings().setJavaScriptEnabled(true);

wv.loadUrl("http://en.wikipedia.org/wiki/Book");

这篇关于Android的WebView中不能正确显示网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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