Issue
I want that the webview display the picture from the resource and html code from the database but only the html code from the database works fine.
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);
I also tried to use an image from the asset folder but that did not work either.
String img = "<img src =\"file:///android_asset/picture.png\" width=\"100\" height=\"100\" />";
Solution
You can use loadDataWithBaseURL.
String htmlString = <html><body><img src="file.png"></body></html>
myWebView.loadDataWithBaseURL("file:///android_asset/", htmlString, "text/html", "UTF-8", null);
The first argument, must point where the image must be.
Answered By - Rigotti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.