How to put an image from a drop-down folder in an HTML file

I have an HTML file in my /res/raw/test.html

and I will show it in web view using the following code

WebView wbview = (WebView)findViewById(R.id.webView1); InputStream fin; try { fin = getResources().openRawResource(R.raw.manual); byte[] buffer = new byte[fin.available()]; fin.read(buffer); fin.close(); wbview.loadData(new String(buffer), "text/html", "UTF-8"); } catch (IOException e) { e.printStackTrace(); } 

And this is my HTML file code

 <html> <p> Lorem ipsum dolor sit amet, </p> <table> <tr> <td> <img src=\\"file:///android_asset/test_image2.jpg\"/> <img src="test_image2.jpg" width="50px" alt="Hi"> <img src=\"res/drawable/test_image.png"/> <img src="file:///android_res/drawable/test_image.png" /> <img src=\"file:///android_res/drawable/test_image.png"\ /> </td> </tr> </table> </html> 

I want to display the image from the folder of my resource in my html file ... I tried all the opportunity to still not work. It just displays HTML text, but for the image, I have no idea how to display it.

Please help me

+8
android
source share
1 answer

You can load your html page from the Android resources folder as shown below.

 WebView webView = new WebView(this); webView.loadUrl("file:///android_asset/manual.html"); setContentView(webView); 

and also you need to do your html as below.

  <html> <p> Lorem ipsum dolor sit amet, </p> <table> <tr> <td> <img src="file:///android_asset/test_image2.jpg"/> <img src="file:///android_asset/test_image2.jpg" width="50px" alt="Hi"> <img src="file:///android_res/drawable/test_image.png"/> <img src="file:///android_res/drawable/test_image.png" /> <img src="file:///android_res/drawable/test_image.png" /> </td> </tr> </table> </html> 
+16
source share

All Articles