[英]How to load a picture from the resource and html into webview?
我希望webview顯示資源中的圖片和數據庫中的html代碼,但是只有數據庫中的html代碼才能正常工作。
WebView wv = (WebView) findViewById(R.id.wv);
String city = "lichtenstein";
String img = "<img src =\"file://res/drawable/picture.png\" width=\"100\" height=\"100\" />";
String dbHTML = cursor.getString(cursor.getColumnIndex(Database.COLUMN_HTML));
String webdata = "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />" + img + "<br />" + "<span style=\"color:#064896;font-weight:bold;\">" + city + " </span>" + dbHTML;
wv.loadData(webdata, "text/html; charset=UTF-8", null);
我也嘗試使用資產文件夾中的圖像,但這也不起作用。
String img = "<img src =\"file:///android_asset/picture.png\" width=\"100\" height=\"100\" />";
您可以使用loadDataWithBaseURL 。
String htmlString = <html><body><img src="file.png"></body></html>
myWebView.loadDataWithBaseURL("file:///android_asset/", htmlString, "text/html", "UTF-8", null);
第一個參數必須指向圖像必須位於的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.