简体   繁体   中英

Webview in android does not load image from res/drawable

This is my code:

webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            view.loadUrl("file:///android_res/drawable/sale_screen_20170912.jpg");
        }
    });

I want to load an image from drawable resource when receiving an error from webview. But this is what I got when try to load this image from drawable folder.

在此处输入图像描述

API level of the project is 17.

Try this

        webView.loadDataWithBaseURL("file:///android_res/drawable/", "<img src='sale_screen_20170912.jpg' />", "text/html", "utf-8", null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM