I am trying to set an image to a WebView
for my app.
I am using the below code to set the image to my WebView
,
String imageUrl = " file:///android_res/drawable/dinner_menu.png";
WebView wv = (WebView) findViewById(R.id.yourwebview);
wv.getSettings().setBuiltInZoomControls(true);
wv.loadUrl(imageUrl);
This works fine for Android 2.2 and higher.
But if I try to run the code in 2.1 or lower, it shows an error as,
The requested file was not found /android_res/drawable/dinner_menu.png
.
Can anyone help me out.
Try putting your image in your assets folder, and load it using:
WebView webView = new WebView(this);
webView.loadUrl("file:///android_asset/dinner_menu.png");
setContentView(webView);
It should work on earlier versions of Android, but you'll need to manually manage using different versions of your image for different screen sizes / densities.
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