简体   繁体   English

Android中的WebView不显示网页样式

[英]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. 我正在尝试使Android应用程序在WebView中显示网站,但是只有网站首页实际上可以通过WebView正确显示内容,其他页面完全无视网站样式,并使用白色背景和蓝色默认超链接显示内容。 I tested the same type of app on iOS and it works fine there. 我在iOS上测试了相同类型的应用程序,并且在这里可以正常工作。 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. 如果您将WebView中的“单列设置”保留下来,则将其完美地工作。

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. 如果您尚未保留“单列”设置,但仍无法使用,请检查是否启用了JavaScript,否则请启用。

myWebView.getSettings().setJavaScriptEnabled(true);

Android WebView requires you to explicitly enable javascript. Android WebView要求您显式启用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. 页面中的样式可能是通过javascript加载的,通常,没有它,网站就无法正常工作,因此启用它很重要,并且除此之外还可以解决您的问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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