简体   繁体   中英

WebView in Android not showing web page styles

I am trying to make an Android app display a website in a WebView, but only the website home page actually show content properly via the WebView, the other pages completely disregard the website styles and display content with a white background and blue default hyperlinks. I tested the same type of app on iOS and it works fine there. What can I do about it?

Android版

在此处输入图片说明

This is the method:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView myWebView = (WebView) findViewById(R.id.webView);
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("http://www.awesomestories.com");
}

If you have kept Single Column Setting in WebView remove it, it will work just perfect.

myWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

If you have not kept Single Column setting and still its not working, then check that you have enabled JavaScript or not, if not then enable it.

myWebView.getSettings().setJavaScriptEnabled(true);

Android WebView requires you to explicitly enable javascript. Styles in the page may be loaded via javascript, and generally websites don't tend to work good without it, so enabling it is important and might solve your problem in addition to that.

myWebView.getSettings().setJavaScriptEnabled(true);

Settings should be set.
Tricks Like this:

    WebSettings settings = webview.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setPluginState(PluginState.ON);
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM