WebView页面中使用res中图片的方法:
<img id="img" src="file:///android_res/drawable/ic_launcher.png" />
附测试页面:
<!doctype html> <html> <head> <meta charset="utf-8"> <script type="text/javascript"> function loadimage(imageName) { Android.run("log", imageName); var img = document.getElementById("img"); img.src="file:///android_res/drawable/" + imageName; } function init() { Android.run("log", "init"); } </script> </head> <body style="background-color:white;" onload="init()"> <img id="img" src="" /> </body> </html>
Android端代码:
private void loadimage(String imageName) { String url = "javascript:loadimage(‘" + imageName + "‘);"; Log.e("Javascript Log", url); webview.loadUrl(url); }
调用:
loadimage("ic_launcher.png");
时间: 2024-12-05 02:12:42