ANDROID- WebView未按预期显示网页

时间:2018-03-15 10:15:45

标签: java android android-activity webview web

我的网页(CYNX.ML/U1.html)在所有其他浏览器中都能完美显示,但是我正在使用WebView将其显示给用户,这似乎表明它已损坏。

这就是它在WebView上显示的方式 - http://prntscr.com/irhosm

有什么方法可以解决这个问题?它似乎在所有移动网络浏览器上都能完美展示 - 包括Chrome,Dolphin Web浏览器,UC网络浏览器

* MainActivity.java的代码 -

 package com.sirseni.simpleandroidwebviewexample;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WebView myWebView = (WebView) findViewById(R.id.myWebView);
        myWebView.loadUrl("http://cynx.ml/U1.html");
        myWebView.setWebViewClient(new MyWebViewClient());
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUserAgentString("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
    }

    // Use When the user clicks a link from a web page in your WebView
    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getHost().equals("www.centerend.com")) {
                return false;

            }

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    }
}

**更新:**必须告知我觉得WebView在页面的css样式方面存在轻微问题,但Google似乎将其显示为100%移动兼容。有什么想法吗?

0 个答案:

没有答案