开发者

Setting Url to a WebView

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 fi开发者_开发知识库ne 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜