简体   繁体   中英

Android webview is not displaying image

I was just learning how to display a html file using webview Android.

But the image containing on html file are not displaying on the Android version greater than kitkat.

My code is:

MainActivity.java inside oncreate

WebView web = (WebView)finditembyid(R.id.webview1);

Web.loadurl("file:///android_asset/index.html");

My html file contains:

  <img src="image.png">

Inside my assets folder:

Index.html
Image.png

I tried changing the src on image tag by:

Src="file:////android_asset/image.png
Src="/android/image.png"

But these are not working. What should I do?

Try this code out,its a sample code in which i have opened content in webview thats contains a hyperlink and image as well. It works for me if there is a link it will create it automatically and if there in image tag then it will display image in webview.

String about_us_description_new = "<html><body style=color:black;>" + "<p align=\"justify\">" + about_us_description + "</p>" + "</body></html>";
                webView2.setBackgroundColor(Color.TRANSPARENT);
                webView2.getSettings().setJavaScriptEnabled(true);
                webView2.loadDataWithBaseURL(null, about_us_description_new.toString(), "text/html", "utf-8", null);

replace your content with "about_us_description", i have stored content in a string variable as about_us_description and then did my work .

Hope this helps you out

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