我正在将 html 文件从 sdcard 加载到 webview,但是当我从 sdcard 加载 html 到 webview 时,它不会正确加载 css 和图像,视频也不会在 webview 中加载。
Work With 4.4 kitkat and chrome version
Not Work With below 4.4 kitkat version
我已经尝试过在 loadUrl 和 loadDatawithBaseurl 中直接传递 url 的两种方式,但没有任何适合我的方法。
mWebview=(WebView)findViewById(R.id.webview);
mWebview.getSettings().setJavaScriptEnabled(true);
mWebview.setWebChromeClient(new WebChromeClient());
mWebview.setWebViewClient(new WebViewClient());
mWebview.loadUrl("file:///storage/emulated/0/13119/news66.html");
也试试这个
data=getHTMLDataBuffer("file:///storage/emulated/0/13119/news66.html");
mWebview.loadDataWithBaseURL("file://"+Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/13119/",data,"text/html","UTF-8", null);
Chrome ScreenShot
Webview ScreenShot
最佳答案
看起来您的网页中有一些媒体(视频、图像)尚未加载。
尝试:
为您的应用添加互联网权限。媒体未加载可能是因为它来自互联网,但您没有互联网许可,因此 webview 不会加载它(这可以解释为什么它在 Chrome 中加载正常)
<所有 HTML 文件都会发生这种情况吗? webview 不支持一些新标准,但 chrome 支持,这可以解释为什么它不起作用。
尝试在不同的浏览器中加载您的 HTML 文件,看看它是否有效。
您可以将您的 HTML 文件上传到某处(先将其压缩),我会全部查看。
编辑:您的 HTML 有问题。在 news66 中我看到:
body { margin:0;background: url("TS-INFO-16-9-HD.png") no-repeat scroll center center / 1920px 100% rgba(0, 0, 0, 0); height:100% important; overflow:hidden; }
更改为:
body { margin:0;background: url("TS-INFO-16-9-HD.png") no-repeat scroll center center; height: 100%; }
而且它有效。其他所有类似。
关于javascript - 从 sdcard 加载 html 到 android 中的 webview 时出现 HTML、css、js 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28341289/