简体   繁体   English

Android中本地Webview页面中的在线图像

[英]Online images in local Webview page in Android

I have a webview showing a local html page resource in a string like this: 我有一个webview以这样的字符串显示本地html页面资源:

 <p>Hi.</p> <p><img alt="" src="http://ADRESS.COM/image.jpg" style="height:300px; width:400px" /></p> 

and doing that with this code: 并使用以下代码进行操作:

    WebView web = (WebView) findViewById(R.id.web);
    web.getSettings().setJavaScriptEnabled(true);
    web.loadDataWithBaseURL("",notice,"text/html","UTF-8","");

The page contains some images with online src. 该页面包含一些带有在线src的图像。 but in android WebView the images doesn't load. 但在android Webview中,图像不会加载。 (in chrome it works). (在Chrome中有效)。 What I should do? 我该做什么?

thanks. 谢谢。

Add these two lines in your code. 在代码中添加这两行。

web.getSettings().setLoadsImagesAutomatically(true);
web.getSettings().setDomStorageEnabled(true);

Instead of using web.loadDataWithBaseURL("",notice,"text/html","UTF-8",""); 而不是使用web.loadDataWithBaseURL("",notice,"text/html","UTF-8",""); simply load your website url as follows 只需按以下方式加载您的网站网址

web.loadUrl("http://www.google.com");

if you want load your local html page. 如果要加载本地html页面。 Create asset directory android then put your html file in asset folder and and set it as follows 创建资产目录android,然后将您的html文件放入资产文件夹中,并进行如下设置

web.loadUrl("file:///android_asset/yourFile.html");

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

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