开发者

Android WebView does not display web page correctly

开发者 https://www.devze.com 2023-03-10 12:39 出处:网络
I have simple WebView code like this: WebView wv = (WebView) findViewById(R.id.webview1); wv.loadUrl(\"http://en.wikipedia.org/wiki/Book\");

I have simple WebView code like this:

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

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

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.

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

开发者_开发知识库

Does any one has solution for this?


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");


Try:

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


Try This,

    wv = (WebView)findViewById(R.id.webview1);
    WebSettings webSettings = wv.getSettings();
    webSettings.setJavaScriptEnabled(true);
    wv.loadUrl("http://en.wikipedia.org/wiki/Book");
    wv.setWebViewClient(new WebViewClient());
0

精彩评论

暂无评论...
验证码 换一张
取 消