@Android display /res/viewable in WebView

前端 未结 7 1444
耶瑟儿~
耶瑟儿~ 2020-11-29 05:51

I am throwing HTML to a webview to render. In the HTML I need to load an image that I have in /res/drawable.

I have /res/drawable/my_image.png

7条回答
  •  旧巷少年郎
    2020-11-29 06:44

    user302750,

    Your method is incorrect. res/drawable/banner300.jpg should be file:///android_res/drawable/banner300.jpg.

    banner300.jpg can be in one of the following locations in your project, and android will automatically load the correct one for the device you're using.

    • res/drawable/banner300.jpg
    • res/drawable-ldpi/banner300.jpg
    • res/drawable-mdpi/banner300.jpg
    • res/drawable-hdpi/banner300.jpg
    • res/drawable-xhdpi/banner300.jpg

    The assets folder is for generic resources that you don't need different versions of. An example might be an XSL template, or something of that nature.

    MikeNereson, your response to your problem is also incorrect, drawable resources should be contained in the res directory.

    Here's an example from my own project. I output html, exactly like this:

    
    

    If using an ldpi device, I get the ldpi image, if using hdpi or mdpi, I get the appropriate one for those as well. Android resolves file:///android_res/drawable/stats_btn.png to one of the following resources that I have in my project.

    • ./res/drawable-ldpi/stats_btn.png
    • ./res/drawable-hdpi/stats_btn.png
    • ./res/drawable-mdpi/stats_btn.png

提交回复
热议问题