Though webview is meant to load urls, it can also be used to load images.
To load an image in webview, we can directly write the url of the image. Even animated gifs can be loaded directly to webview:
WebView webview1 loadUrl http://.....jpg
We can modify the width and height of this image by using following code:
WebView webview1 loadUrl data:text/html,<img width=100% height="" src="(imageUrl)">
We can make it fit the width of the screen by setting width=100% in above code.
We can also load the images added using image manager in Sketchware, with following code:
WebView webview1 loadUrl file:///android_res/drawable/IMAGENAME
To load an image in webview, we can directly write the url of the image. Even animated gifs can be loaded directly to webview:
WebView webview1 loadUrl http://.....jpg
We can modify the width and height of this image by using following code:
WebView webview1 loadUrl data:text/html,<img width=100% height="" src="(imageUrl)">
We can make it fit the width of the screen by setting width=100% in above code.
We can also load the images added using image manager in Sketchware, with following code:
WebView webview1 loadUrl file:///android_res/drawable/IMAGENAME
Note that animations do not work with this method.
Another way to load an image in webview is to put an image in sounds folder of app using file manager and then modify resource file of the app to include the name of the image. After that the image can be loaded in webview using following block:
WebView webview1 loadUrl file:///android_res/raw/IMAGENAME
This method can be used to insert and load .gif images in webview. This method can also be used to insert and load HTML files in webview.
The image can also be loaded from assets folder. The assets folder can be created by editing the apk file in APK Editor Pro and then the image can be added to that folder. To load the image from assets folder we can use following code:
WebView webview1 loadUrl file:///android_asset/IMAGENAME
0 komentar:
Posting Komentar