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
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With