Android Development: Using Image From Assets In A WebView's HTML

南楼画角 提交于 2019-11-26 22:13:28

Put your Logo into the assets directory eg: assets/logo.png

Then load your html with:

webView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "utf-8", null);

Reference your img like:

<img src="logo.png">

Store the images in assets folder:

Read the image in the html from assets with file:///android_asset/

for example:

String sHtmlTemplate = "<html><head></head><body><img src=\"file:///android_asset/img/mybadge.png\"></body></html>";

load inside the WebView:

webView.loadDataWithBaseURL(null, sHtmlTemplate, "text/html", "utf-8",null);

dump them into assets folder and just put in the html

<img src="filename.png">

simple as that

You can reference assets with this URL syntax:

file:///android_asset/YourAssetFilename

Put your Logo into the assets directory Example : assets/logo.png

Then

String imgData="<img src=home.png>";

webView.loadDataWithBaseURL("file:///android_asset/", imgData, "text/html", "utf-8", null);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!