Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put image from drawable folder at HTML file

Tags:

android

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

and i show it in web view using 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 code of my HTML file

<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 my resource folder in my html file... i tried all possibility still not work. It's just show a HTML text but for a image i don't have idea how to show it

Please help me

like image 698
Aldy Chrissandy Avatar asked Apr 18 '12 08:04

Aldy Chrissandy


People also ask

How do I insert a picture into a drawable file?

Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import. Figure 3: Select Import Drawables from the dropdown menu.

How do I add an image to a drawable XML file?

Step 1: In this method first of all in your system find your required images and copy the image as we do normally. Step 2: Then open the Android Studio go to the app > res > drawable > right-click > Paste as shown in the below figure. Step 3: Then a pop-up screen will arise like below.

Where do I put images in Android Studio?

In Android Studio, click on View > Tool Windows > Resource Manager in the menus or click on the Resource Manager tab to the left of the Project window. Click the + below Resource Manager, and select Import Drawables.


1 Answers

You can load your html page from android assets folder like below code.

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

and also you need to make your html like this 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>
like image 188
Herry Avatar answered Nov 15 '22 12:11

Herry