在Android webview中,我有js在边距的右侧添加了一个div(在webview上),现在当我添加带有背景颜色的div时,这可以正常工作。
当想要在 div 上添加背景图像时,这似乎不起作用。
这是我呈现 div 的 js
var div = document.createElement('div');
div.style.width = "20px";
div.style.height = "20px";
div.style.position = "absolute";
div.style.top = yPos + "px";
div.style.right = "5px";
div.style.backgroundColor = col;
div.style.backgroundImage = "url(file:///android_asset/images/ic_menu_notes_pressed.png)";
document.body.appendChild(div);
背景颜色加载正常,但没有显示图像。
我的图像位于 /assets/images/ic_menu_notes_pressed.png
更新,使用以下解决方案 () base64
js文件
var img = document.createElement('img');
img.style.width = "50px";
img.alt = "Hello";
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAABbUlEQVRoQ+1YvUoDQRD+ZoNioSD25tw0Qiz0AXwQQWw0QdRK0FIQQXvRRgSfxgfQ0spKC9s0FrmMwx1JsNC97LrmFibNQW527/u7mbsjJP6jxPFDCUzbQXVAHQhUQCMUKGDwcnUgWMLADaI4wIdr88h7TQwoc+LL5x7p4aXnrPuh4M8JcHdlCzBLIG6D+cgJzNAG3b0+O+v+gwB3s22A7gX8mZCwyRBgQY2O3RHg1yLUohxPkiHA5zB4z47BdCXgZwunkyLQsacC+FJgz4ximgKBQvk3uwfwzTfwBQsWUqZV63ugjM6yBRpj5YcW5P0P+fui3gQOmi30ze0v7a8t59xzYFptlPftOgb85Nu/R+uUgKeE6sBQOI2QRshTAY1QqYD3+4B2IY2QRkifhcoM6CT2nEPpt9Hd1QU0Pjc9+Y+X1e3DVjChCTfwnsQTXidauRKIJm3FjdWBikJFK1MHoklbcWN1oKJQ0cqSd+ALnjXMMUm0ItgAAAAASUVORK5CYII=";
document.body.appendChild(img);