码迷,mamicode.com
首页 > 移动开发 > 详细

[Android] 在WebView的页面中直接使用res中的图片

时间:2017-04-24 12:28:15      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:方法   element   name   run   java   charset   rip   url   white   

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");

 

[Android] 在WebView的页面中直接使用res中的图片

标签:方法   element   name   run   java   charset   rip   url   white   

原文地址:http://www.cnblogs.com/chenyFish/p/6755678.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!