Android - adding a image in html webview

后端 未结 4 706
被撕碎了的回忆
被撕碎了的回忆 2020-12-21 01:39

Ok so the image i\'m using is called test.png and I have a java class (Cherry.java) and a xml class (cherry.xml) Also I have a html file in the /res/raw folder called htmlt

相关标签:
4条回答
  • 2020-12-21 01:50

    Create this directory assets/www

    then place your html and image etc inside the www folder. And use the following code.

    Cherry.java

    webview.loadUrl("file:///android_asset/www/htmltest.html");
    

    htmltest.html

    <img border="0" src="../res/drawable-hdpi/test.png" alt="nothing" width="304" height="228" />
    
    0 讨论(0)
  • 2020-12-21 01:58

    Just modify the image path

    From:

    file:///android_drawable/test.png

    To:

    file:///android_res/drawable/test.png

    0 讨论(0)
  • 2020-12-21 02:03

    If your images are small. Convert them to Base64 codings.

    Explained here: http://dean.edwards.name/my/base64-ie.html

    0 讨论(0)
  • 2020-12-21 02:04

    First of all welcome to stackoverflow.

    Now put your html and image etc inside the Assets folder. And use the following code.

    Cherry.java

    WebView webview = (WebView) findViewById(R.id.abtus_webView);
    webview.loadUrl("file:///android_asset/index.html");
    

    htmltest.html

    <img src="images/abc.png">
    

    I have put the images into the images Folder in Assets folder.This is working for me correct,I hope it helps you.

    0 讨论(0)
提交回复
热议问题